Is it possible to bind to the fill property in the DataMapping for a series like so:
<igChart:Series ChartType="Scatter" DataSource="{Binding Path=MinMaxPoints}" DataMapping="ValueX=X;ValueY=Y;Fill=LineColor">
Where LineColor is a brush specifying the color for the DataPoint. I really need to be able to do this using only xaml and no code-behind.
Yes. It's been in production for a year or more now.
Mike
Have you tested your sample? It tried it, but got no result...
I can't help you do this with absolutely no code behind, but I did find a way that works well with MVVM with minimal code behind.
The trick is that you can't use DataMapping with Fill, but you can with ToolTip and that can be any object. So, if we map a tooltip object that will display the right text, we can also use it to carry along information about Fill, and we can set the fill brush when data binding is complete.
So, let's define a chart, with an event handler for data binding:
<Chart:XamChart Name="xamChart1" Grid.Row="0" Grid.Column="0" View3D="True" DataBind="xamChart1_DataBind">
Now, let's set up the data binding for our series:
<Chart:Series ChartType="Pie" DataSource="{Binding ComplianceValues}" DataMapping="Value = Value; Label = Label; ToolTip = ToolTipAndFill">
When the data binding is complete, the ToolTip property will have been filled in from the ToolTipAndFill property and then the event handler is executed. At this point we can iterate over all of the data points and set the fill value.
private void xamChart1_DataBind( object sender, DataBindEventArgs e )
{
foreach ( DataPoint point in xamChart1.Series[0].DataPoints ) ToolTipAndFill toolTipAndFill = point.ToolTip as ToolTipAndFill;
point.Fill = toolTipAndFill.Brush;
}
The ToolTipAndFill class is as follows:
public class ToolTipAndFill
public string ToolTip { get; set; }
if ( Fill is Color )
return (Color) Fill; return (Color) ColorConverter.ConvertFromString( Fill.ToString() ); }
{return Fill as Brush ?? new SolidColorBrush( Color );
public override string ToString() return ToolTip;
Note that Fill is an object and can be set to a Brush, a Color, or any string which can be converted to a Color (see below).
The rest is pretty straight foreward. Here's the ComplianceValues class:
public class ComplianceValues
public int Value { get; set; }
Here's the propery in my view model that is being bound to the chart:
public ComplianceValues[] ComplianceValues { get; set; }
And here's how I initialize the ComplianceValues to be databound to the pie chart (hard coded for this example). Note the Fill values are strings which can be converted to Color values and from there to a Brush:
ComplianceValues = new[] new ComplianceValues { Label = "Non-compliant", Value = 1, ToolTipAndFill= new ToolTipAndFill { ToolTip="25% Non-compliant", Fill= "#FFD70005"} },
I hope all this comes through OK.
Hello,
Currently this is not supported because the DataPoins collection for each series is readonly property. You can't make e.g. your own collection that derives from DataPointsCollection and set it to the DataPoins of particular Series object. If you would like to add such feature in the next releases please submit a feature request on the link below:
(http://devcenter.infragistics.com/Protected/RequestFeature.aspx)
-Vlad
I understand that would work but that would set the Fill for the entire series where I want to set the Fill for the individual datapoint.
Can I not have a serires with different color datapoints? Is it not possible to do that through this type of binding?
Or is there a way for me to create a datapointcollection in code and bind to that?
My solution is using the Model-View-ViewModel approach so the view model creating the data has no access to the chart that is in the xaml of the view.
thanks for your help.