<chart:DoughnutSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue">
<chart:DoughnutSeries.ColorModel>
<chart:ChartColorModel Palette="Custom" CustomBrushes="{Binding Colors}"/>
</chart:DoughnutSeries.ColorModel>
</chart:DoughnutSeries> |
public class ViewModel
{
public ChartColorCollection Colors { get; set; }
public ViewModel()
{
Colors = new ChartColorCollection();
foreach (var value in Data)
{
if (value.YValue < 20)
Colors.Add(Color.Red);
else if (value.YValue > 21 && value.YValue < 60)
Colors.Add(Color.Green);
else
Colors.Add(Color.Blue);
}
}
}
|
<chart:DoughnutSeries ItemsSource="{Binding MyDataList}" XBindingPath="XValue" YBindingPath="YValue">
<chart:DoughnutSeries.ColorModel>
<chart:ChartColorModel Palette="Custom" CustomBrushes="{Binding MyColors}"/>
</chart:DoughnutSeries.ColorModel>
</chart:DoughnutSeries> |
public class ViewModel : INotifyPropertyChanged
{
…..
private ChartColorCollection myColors;
public ChartColorCollection MyColors
{
get { return myColors; }
set
{
myColors = value;
OnPropertyChanged("MyColors");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyname)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
}
}
|