We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change colors of specific data points in the chart

Platform: WPF |
Control: SfChart

This KB explains how to bind color to each item of the series from ViewModel.

You can specify the desired color for each segment of the chart series through the property SegmentColorPath. This property allows you to map each segment in a chart series to a specific color in ViewModel.

 

You can specify the desired color in ViewModel as in the following code example.

 

C#

public class ViewModel
{
    public ObservableCollection<Model> Data { get; set; }
 
    public ViewModel()
    {
        Data = new ObservableCollection<Model>();
 
        Data.Add(new Model() { XValue = "Apple", YValue = 40, Color = Brushes.Tomato });
        Data.Add(new Model() { XValue = "Orange", YValue = 30, Color = Brushes.Orange });
        Data.Add(new Model() { XValue = "Grape", YValue = 25, Color = Brushes.Violet });
        Data.Add(new Model() { XValue = "Blueberry", YValue = 15, Color = Brushes.MediumSlateBlue });
        Data.Add(new Model() { XValue = "Guava", YValue = 32, Color = Brushes.LawnGreen });
        Data.Add(new Model() { XValue = "Banana", YValue = 55, Color = Brushes.LightGoldenrodYellow });
    }
}

 

The following code explains how to create charts, where each segment has its color bound to the property of the underlying data object.

XAML

<chart:SfChart >
    <chart:PieSeries SegmentColorPath="Color" ItemsSource="{Binding Data}" XBindingPath="XValue" YBindingPath="YValue" />
</chart:SfChart>

 

C#

PieSeries series = new PieSeries()
{
    ItemsSource = viewModel.Data,
    XBindingPath = "XValue",
    YBindingPath = "YValue",
    SegmentColorPath = "Color"
};
chart.Series.Add(series);

Output:

Binding colors based on the data value for each series segment

 

2X faster development

The ultimate WPF UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile