Articles in this section
Category / Section

How to add custom color model to WPF Chart (SfChart)?

1 min read

WPF Chart (SfChart) Provides support to customize the color of chart series. You can customize any color for each individual segment by setting the Palette property to Custom. You can define the required list of custom brushes and assign them to 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)));

 

WPF Chart with Custom Color

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied