<chart:SfChart.Series>
<chart:DoughnutSeries ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue" >
<chart:DoughnutSeries.ColorModel>
<chart:ChartColorModel Palette="Custom" CustomBrushes="{Binding Colors}" />
</chart:DoughnutSeries.ColorModel>
</chart:DoughnutSeries>
</chart:SfChart.Series> |
public class ViewModel
{
public ChartColorCollection Colors { get; set; }
public ViewModel()
{
Colors = new ChartColorCollection();
Colors.Add(Color.Red);
Colors.Add(Color.DarkViolet);
Colors.Add(Color.GreenYellow);
Colors.Add(Color.Blue);
}
} |
I have a simular question about changing the color of the chart slices. lets say i have the following class:
List<Car> Cars
{
new Car { Category = "BMW", Amount = 2, Color = Green},
new Car { Category = "Audi", Amount = 4, Color = Blue },
new Car { Category = "Mercedes", Amount = 1, Color = Yellow },
}
Where Category is the xBindingPath and Amount is the yBindingPath. How can i bind the Color parameter to the the slices of the chart?
<chart:SfChart.Series>
<chart:DoughnutSeries ItemsSource="{Binding Cars}"
XBindingPath="Category"
YBindingPath="Amount"
DataMarkerPosition="OutsideExtended">
<chart:DoughnutSeries.DataMarker>
<chart:ChartDataMarker/>
</chart:DoughnutSeries.DataMarker>
<chart:DoughnutSeries.ColorModel>
<chart:ChartColorModel Palette="Custom"
CustomBrushes="{Binding Colors}" />
</chart:DoughnutSeries.ColorModel>
</chart:DoughnutSeries>
</chart:SfChart.Series> |
public ViewModel()
{
Cars = new ObservableCollection<Car>()
{
new Car { Category = "BMW", Amount = 2, Color = Color.Green },
new Car { Category = "Audi", Amount = 4, Color = Color.Blue },
new Car { Category = "Mercedes", Amount = 1, Color = Color.Yellow },
};
Colors = new ChartColorCollection();
foreach(var item in Cars)
{
Colors.Add(item.Color);
}
} |