How to set custom colors for a series using the ColorModel property in UWP Chart?
This article explains how to apply a custom set of colors to a chart series using the ColorModel property in an UWP Chart. By defining a collection of custom brushes, you can override the default palette and have precise control over the series colors. This can be achieved either programmatically in C# or declaratively in XAML.
Option 1: You can define a custom color palette in the code-behind. First, create an instance of ChartColorModel and add SolidColorBrush objects to its CustomBrushes collection. Then, set the series Palette to Custom and assign your ChartColorModel instance to the ColorModel property of the series.
ChartColorModel colorModel = new ChartColorModel();
colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Red));
colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.RosyBrown));
colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.RoyalBlue));
colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.SaddleBrown));
colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Salmon));
chart.Series[0].Palette = ChartColorPalette.Custom;
chart.Series[0].ColorModel = colorModel;Option 2: Alternatively, you can define the custom colors directly in XAML. Set the Palette property of the series to Custom and define the ChartColorModel within the series tags. Add the desired SolidColorBrush elements to the CustomBrushes collection.
<syncfusion:ColumnSeries ItemsSource="{Binding TestingModel}" XBindingPath="X" YBindingPath="Y1" Palette="Custom">
<syncfusion:ColumnSeries.ColorModel>
<syncfusion:ChartColorModel>
<syncfusion:ChartColorModel.CustomBrushes>
<SolidColorBrush Color="Red"/>
<SolidColorBrush Color="RosyBrown"/>
<SolidColorBrush Color="RoyalBlue"/>
<SolidColorBrush Color="SaddleBrown"/>
<SolidColorBrush Color="Salmon"/>
</syncfusion:ChartColorModel.CustomBrushes>
</syncfusion:ChartColorModel>
</syncfusion:ColumnSeries.ColorModel>
</syncfusion:ColumnSeries>Conclusion
I hope you enjoyed learning how to set custom colors for a series using the ColorModel property in the UWP Chart.
You can refer to our UWP Chart’s feature tour page to know about its other groundbreaking feature representations. You can also explore our UWP Chart documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our UWP Charts and other UWP components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!