Bind Color on ColumnSeries

Is it possible to bind a color on a column series based on what the x axis value is?

1 Reply

MK Muneesh Kumar G Syncfusion Team June 4, 2018 09:55 AM UTC

Hi Caleb, 
 
Thanks for using Syncfusion products.  
 
You can achieve this requirement by setting custom palette to series with custom colors, which is created based on x axis value as per the below code snippet.  
 
Code snippet [XAML]: 
  <chart:ColumnSeries XBindingPath="XValue"  
                                        YBindingPath="YValue1"  
                                        ItemsSource="{Binding Data}"> 
                        <chart:ColumnSeries.ColorModel> 
                            <chart:ChartColorModel Palette="Custom" CustomBrushes="{Binding Colors}"/> 
                        </chart:ColumnSeries.ColorModel> 
                    </chart:ColumnSeries>  
 
Code snippet [C#]: 
 
for (int i = 0; i < 10; i++) 
           
                
                Data.Add(new Model() {XValue=i,YValue1=rd.Next(0,20),YValue2=rd.Next(0,20) }); 
 
                if (i < 5) 
                    Colors.Add(Color.Red); 
                else 
                    Colors.Add(Color.Green); 
 
           
            
 
We have prepared a sample based on this, please find the sample from the following location.  
 
 
Please refer below user documentation for more details about custom palette.  
 
 
Please let us know if you have any queries.  
 
Thanks,
Muneesh Kumar G 


Loader.
Up arrow icon