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
close icon

Set color of LineSeries depends on data

I want the color of lineseries depends on the data value, if current value >0, the color should be green, if the current value <0, the color should be red.
How to implement?

3 Replies

SA Santhiya Arulsamy Syncfusion Team October 16, 2015 01:02 PM UTC

Hi William,

Thanks for contacting Syncfusion support.

We have achieved your requirement by using the custom palette feature. We have prepared the sample based on your requirement.

Sample: LineSeries_120799

Please refer the below links for further information.

Documentation: http://help.syncfusion.com/wp8/sfchart/styling-and-customization

KB : https: //www.syncfusion.com/kb/5126/how-to-define-the-fill-color-for-each-datapoint-from-itemssource

Thanks,

Santhiya A


WI William October 16, 2015 01:48 PM UTC

Hi Santhiya

Thanks for support, I found such code in your sample:

            for (int i = 0; i < viewModel.DataPoint.Count; i++)
            {
                if (viewModel.DataPoint[i].YData > 0)
                    chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Green));
                else
                    chart.Series[0].ColorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Red));
            }

Is that the only way to set color dynamically? Is there any easier way? like use Data binding the SolidColorBrush in XAML?


SA Santhiya Arulsamy Syncfusion Team October 19, 2015 03:00 PM UTC

Hi William,

We had achieved your requirement by using data binding in the ChartSeries ColorModel property. We have modified the sample based on your requirement.

Please find the sample from the below link.
LineSeries_120799_(2)

Thanks,

Santhiya A.

Loader.
Live Chat Icon For mobile
Up arrow icon