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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

color of a series

Thread ID:

Created:

Updated:

Platform:

Replies:

130176 Apr 26,2017 01:10 PM UTC May 1,2017 08:27 AM UTC UWP 3
loading
Tags: SfChart
Theo
Asked On April 26, 2017 01:10 PM UTC

Hi,

I am using a custom color pallet in SF UWP chart control. I have 5 colors in it (red, blue, green, yellow, orange). This work good. However, if I have null values for a series, then that series I think it not on the chart, and the color it should have taken goes to the next series that does get charted. This is a bit ...well...confusing for me. Is there a way to not have this happen? I would like the colors I dedicate to the series to stay, even if a series is not plotted because it has currently null values.
The moment I do give it values (in a live mode on timer for example), then the colors shifts. Am I doing something wrong?
I would like a suggestion in vb.net, but c# is also fine. Thanks.

Devi Aruna Maharasi Murugan [Syncfusion]
Replied On April 27, 2017 12:46 PM UTC

Hi Theo, 
  
Thanks for contacting Syncfusion Support. 
  
We would like to inform you that, if you have set null for chart series, then the series will not be added into the ChartSeriesCollection. 
  
Therefore, in your case, the first color of palette has applied to second series (as series in added first to ChartSeriesCollection).  
  
However, we can achieve your requirement by initializing the series alone for null data values and can dynamically setting other properties such as ItemsSource when data values loaded. So that, you can retain the pre-defined color for the series in custom color model. 
  
Please find the code snippet, 
  
C# 
chart = new SfChart() 
            { 
                Margin = new Thickness(10), 
                Palette = ChartColorPalette.Custom 
            }; 
            ChartColorModel  colorModel= new ChartColorModel(); 
            colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Red)); 
            colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Green)); 
            colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Blue)); 
            colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Yellow)); 
            colorModel.CustomBrushes.Add(new SolidColorBrush(Colors.Orange)); 
            chart.ColorModel = colorModel; 
 
            SplineSeries series1 = new SplineSeries(); 
            chart.Series.Add(series1); 
            SplineSeries series2 = new SplineSeries() 
            { 
                ItemsSource = view.Collection, 
                XBindingPath = "XValue", 
                YBindingPath = "Value2" 
            }; 
            chart.Series.Add(series2); 
            SplineSeries series3 = new SplineSeries() 
            { 
                ItemsSource = view.Collection, 
                XBindingPath = "XValue", 
                YBindingPath = "Value3" 
            }; 
            chart.Series.Add(series3); 
            SplineSeries series4 = new SplineSeries() 
            { 
                ItemsSource = view.Collection, 
                XBindingPath = "XValue", 
                YBindingPath = "Value4" 
            }; 
            chart.Series.Add(series4); 
            SplineSeries series5 = new SplineSeries() 
            { 
                ItemsSource = view.Collection, 
                XBindingPath = "XValue", 
                YBindingPath = "Value5" 
            }; 
            chart.Series.Add(series5); 
            mainGrid.Children.Add(chart); 
        } 
 
        private void Button_Click(object sender, RoutedEventArgs e) 
        { 
            chart.Series[0].ItemsSource = view.Collection; 
            chart.Series[0].XBindingPath = "XValue"; 
            (chart.Series[0] as SplineSeries).YBindingPath = "Value1"; 
        } 
  
  
Please find the output screenshot, 
  
Without Series1 
 
  
With Series1 
 
  
We have prepared sample in C# for your reference and it can be downloaded from below link, 
  
  
Also, you can apply the color values directly to series Interior property instead of applying the custom color palette to retained the series color even some series is not plotted in chart as shown in below code.  
SplineSeries series1 = new SplineSeries(); 
series1.Interior = new SolidColorBrush(Colors.Red); 
  
  
Regards, 
Devi 





Theo
Replied On April 28, 2017 05:43 PM UTC

Hi,

Thanks! The direct set on the series was what I was looking for (simplest for me).

Great!

Santhiya Arulsamy [Syncfusion]
Replied On May 1, 2017 08:27 AM UTC

Hi Theo,

Thanks for the update.

Please let us know if you require any further assistance. We will be happy to assist you.

Thanks,
Santhiya A

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

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

;