Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
255
XamDoughnutChart Brushes
posted

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:

  1. For the OnPropertyUpdated event of the RingSeries, where the PropertyName is ItemsSource pass the RingSeries to a method
  2. Cast the ItemsSource as my class, loop through the list and if the value that is NOT zero or positive, add the corresponding color to a BrushCollection
  3. Set the RingSeries.Brushes to the newly created BrushCollection

  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;

}

Parents Reply Children
No Data