Articles in this section
Category / Section

How to apply different color to the individual data points of a chart series in WPF ?

1 min read

We can apply different color to the individual chart series in a chart. For example, we can apply different color for each bar in the bar chart or for each slice in a Pie chart.

The following code example illustrates applying different colors to the chart series.

private void CreatePresentation() 
//Create a PowerPoint presentation instance 
IPresentation presentation = Presentation.Create();  
//Create a blank slide 
ISlide slide = presentation.Slides.Add(SlideLayoutType.Blank);  
//Add a chart in specific location 
IPresentationChart chart = slide.Charts.AddChart(270, 70, 500, 400); 
//Set the chart data 
chart.ChartData.SetValue(1, 1, "Gender"); 
chart.ChartData.SetValue(1, 2, "Male"); 
chart.ChartData.SetValue(1, 3, "Female"); 
chart.ChartData.SetValue(2, 1, "Accommodation"); 
chart.ChartData.SetValue(3, 1, "Food"); 
chart.ChartData.SetValue(4, 1, "Cosmetics"); 
chart.ChartData.SetValue(5, 1, "Cloths"); 
chart.ChartData.SetValue(6, 1, "Medicines"); 
chart.ChartData.SetValue(2, 2, 30); 
chart.ChartData.SetValue(3, 2, 60); 
chart.ChartData.SetValue(4, 2, 45); 
chart.ChartData.SetValue(5, 2, 55); 
chart.ChartData.SetValue(6, 2, 15); 
chart.ChartData.SetValue(2, 3, 60); 
chart.ChartData.SetValue(3, 3, 30); 
chart.ChartData.SetValue(4, 3, 75); 
chart.ChartData.SetValue(5, 3, 15); 
chart.ChartData.SetValue(6, 3, 35); 
//Specifies the chart title 
chart.ChartTitle = "Expenses";  
//Create a new chart-series with the name 
IOfficeChartSerie serieForMale = chart.Series.Add("Male"); 
//Set the data range for chart 
serieForMale.Values = chart.ChartData[2, 2, 6, 2]; 
//Create a new chart-series with the name 
IOfficeChartSerie serieForFemale = chart.Series.Add("Female"); 
//Set the data range for chart 
serieForFemale.Values = chart.ChartData[2, 3, 6, 3]; 
//Set the data range for category axis 
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 6, 1];  
//Set the chart type as bar chart 
chart.ChartType = OfficeChartType.Bar_Clustered; 
//Set color for the serie of male 
//Set color for the serie of femle 
//Save the presentation into memory stream 
//Close the presentation intstance 
/// <summary> 
/// Set the color to serie datapoints 
/// </summary> 
/// <param name="serie">Represent the serie of the chart</param> 
private void SetColorForSerie(IOfficeChartSerie serie) 
for (int i = serie.Values.FirstRow; i <= serie.Values.LastRow; i++) 
int percentage = Convert.ToInt32(serie.Values.GetValue(i, serie.Values.FirstColumn)); 
if (percentage > 50) 
serie.DataPoints[i - serie.Values.FirstRow].DataFormat.Fill.ForeColorIndex = OfficeKnownColors.Orange; 
serie.DataPoints[i - serie.Values.FirstRow].DataFormat.Fill.ForeColorIndex = OfficeKnownColors.Violet; 


The following screen shot displays the pie chart and bar with different color.


pie chart bar chart


Please find the sample from this link.



I hope you enjoyed learning about how to apply different color to the individual data points of a chart series in WPF.

You can refer to our WPF Presentation featuretour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Presentation example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment