Hi,
I'm using the XamDoughnutChart and attempting to set specific colors for the items that are in the chart. Based on some of the samples that I've seen on your site I'm basically creating a BrushCollection and setting it to the ringSeries.Brushes. I'm having trouble matching the colors to the items and I'm wondering if there is a better way to my approach. Below is a little more detail on what I'm doing:
So the XamDoughnutChart could be bound to a collection that has 4 items in it, 3 of which are positive, so the BrushCollection would have 3 brushes. I've also posted some of my code below. Thanks in advance.
Xaml:
<ig:XamDoughnutChart Grid.Column="4" Grid.Row="0" x:Name="AssetsDoughnutChart"> <ig:XamDoughnutChart.Series> <ig:RingSeries ItemsSource="{Binding Model}" ValueMemberPath="Assets.YearToDate" x:Name="AssetsDoughnutSeries" PropertyUpdated="DoughnutSeries_OnPropertyUpdated" /> </ig:XamDoughnutChart.Series> </ig:XamDoughnutChart>
Code behind:
private void DoughnutSeries_OnPropertyUpdated(object sender, PropertyUpdatedEventArgs e) { if (e.PropertyName == "ItemsSource") UpdateColors(sender as RingSeries); }
private void UpdateColors(RingSeries ringSeries) { var items = ringSeries.ItemsSource as FinancialItemModelList;
if (items == null) return;
var brushes = new BrushCollection(); foreach (var item in items) { var brush = GetColorForProduct(item.Code);
...
if(value <= 0) continue;
if(brush != null) brushes.Add(brush); } ringSeries.Brushes = brushes;
}
Hello,
Thank you for your post. I have been looking into it and I can say that your approach is a good one. If I think of a better one I will let you know.
So how does the control match each item its graphing to the color?
How does it know which is color /brush is available?
I know it's not just by the index, because when it gets to an item that is not being mapped, say item[0] is <= 0, it will not use Brush[0], and if Item[1] > 0 it will use Brush[0].
Is there another way to associate an item to a brush?