How to add custom color model to WPF Chart (SfChart)?
The WPF Chart (SfChart) allows you to customize the color of chart series. By setting the Palette property to Custom, you can apply individual colors to each segment. This customization is done by defining a list of custom brushes which is assigned to the ColorModel property.
XAML
<chart:ColumnSeries Palette="Custom" XBindingPath="Label" YBindingPath="Price" ItemsSource="{Binding List1}"> <chart:ColumnSeries.ColorModel> <chart:ChartColorModel> <chart:ChartColorModel.CustomBrushes> <SolidColorBrush Color="#FF245324"/> <SolidColorBrush Color="#FF202064"/> <SolidColorBrush Color="#FF7E1818"/> <SolidColorBrush Color="#FF9C9C27"/> <SolidColorBrush Color="#FFAC6060"/> <SolidColorBrush Color="#FF4D8B85"/> </chart:ChartColorModel.CustomBrushes> </chart:ChartColorModel> </chart:ColumnSeries.ColorModel> </chart:ColumnSeries>
C#
chart.Series[0].Palette = ChartColorPalette.Custom; chart.Series[0].ColorModel.CustomBrushes = new List<Brush>(); chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Color.FromArgb(250, 0x24, 0x53, 0x24))); chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Color.FromArgb(250, 0x20, 0x20, 0x64))); chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Color.FromArgb(250, 0x7E, 0x18, 0x18))); chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Color.FromArgb(250, 0x9C, 0x9C, 0x27))); chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Color.FromArgb(250, 0xAC, 0x60, 0x60))); chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Color.FromArgb(250, 0x4D, 0x8B, 0x85)));
Output:
Conclusion
I hope you enjoyed learning how to add custom color model to WPF Chart.
You can refer to our WPF Chart feature tour page know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Chart Examples to understand how to create and manipulate data.
For current customers, you can check out our 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 other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!