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

color of a series

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.

5 Replies

DA Devi Aruna Maharasi Murugan Syncfusion Team 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 






TH Theo 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!


SA Santhiya Arulsamy Syncfusion Team 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


GG GGGW September 29, 2019 03:22 AM UTC

The difference between the Interior property and the Stroke property (which doesn't actually change the color of the series stroke) is rather counter intuitive at best and a support nightmare for Syncfusion at worst.


MK Muneesh Kumar G Syncfusion Team September 30, 2019 09:00 AM UTC

Hi Theo, 
 
We have analyzed your query and we have checked the reported problem with already provided sample. Interior works fine with series in SfChart.  
 
Code snippet 
 
   SplineSeries series2 = new SplineSeries() 
            { 
                ItemsSource = view.Collection, 
                XBindingPath = "XValue", 
                YBindingPath = "Value2", 
                Interior=new SolidColorBrush(Colors.Black) 
            }; 
 
 
If you still face any problem, can you update us with SfChart code snippet used in your application or simple sample based on your application scenario, this will help us to provide you a better solution at the earliest. 

 
Thanks, 
Muneesh Kumar G. 


Loader.
Live Chat Icon For mobile
Up arrow icon