Set chart legend and data series color in Pie chart

Hi All,

When I create Pie chart in XlsIO the colors of a legend and therefore of chart segments are selected automatically. How can I set these colors explicitly? When doing it manually in excel I would just select a legend entry and change its fill color. This automatically changes the color of the corresponding chart segment. But in XlsIO I don't see fill color property of IChartLegendEntry or its text area.

Thanks!

5 Replies

SS Sridhar Sukumar Syncfusion Team November 13, 2017 09:02 AM UTC

Hi Artem, 
 
Thank you for contacting Syncfusion support. 
 
As per Microsoft Excel behavior legend entry color is set based on the chart series color. So, the color cannot be set to IChartLegendEntry in XlsIO. We request you to set chart series color to change the legend entries color in XlsIO. Please refer the following code example to set chart series color in XlsIO. 
 
Code snippet: 
chart.Series[0].DataPoints[0].DataFormat.Fill.ForeColor = Color.Green; 
 
Note: In pie chart, legend entry color is set based on chart first series data points color. 
 
Please refer the below UG documentation link to know more about chart in XlsIO. 
 
 
Regards, 
Sridhar. 



AK Artem Kliatchkine November 14, 2017 03:44 PM UTC

Hello Sridhar,

Thanks for your answer. Actually I tried this approach before asking a question. But here is the problem. I create a chart using the following code:

IChartShape chart = _currentWorksheet.Charts.Add();
chart.ChartTitle = string.Format("TEST EXECUTION REPORT ({0})", groupName);
chart.Legend.Position = ExcelLegendPosition.Bottom;
 IChartSerie serie = chart.Series.Add("Series1", ExcelChartType.PieOfPie);
serie.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
serie.DataPoints.DefaultDataPoint.DataLabels.IsCategoryName = true;
serie.Values = _currentWorksheet.Range[tableStartRow, 3, tableStartRow + 4, 3];
serie.CategoryLabels = _currentWorksheet.Range[tableStartRow, 2, tableStartRow + 4, 2];

Then I save a workbook and open it with excel. There is a proper chart there except of legend colors. But: serie.DataPoints is always an empty collection. So I can't set its color. Could it be they are created when a workbook is saved?


Thanks!

Artem Kliatchkine



SS Sridhar Sukumar Syncfusion Team November 15, 2017 01:13 PM UTC

Hi Artem,  
  
Thank you for updating us. 
 
We have analyzed your code snippet and found that the data points are accessed before setting values to chart series. So, we suspect that this is a usage level issue. We have prepared a sample to achieve your requirement which can be downloaded from the following link. 
 
 
If the issue persists, kindly modify the sample to reproduce the issue and share us the modified sample along with the issue reproducing input files which will be helpful for us to give you a prompt solution at the earliest. 
 
Regards,  
Sridhar. 



AK Artem Kliatchkine November 16, 2017 04:10 PM UTC

Hello Sridhar,

Many thanks for your answer. It works now.

Artem Kliatchkine


AV Abirami Varadharajan Syncfusion Team November 17, 2017 05:15 AM UTC

Hi Artem, 

Thank you for updating us. 

We are glad that the issue is resolved at your end. Please let us know if you need any further assistance. 

Regards, 
Abirami. 


Loader.
Up arrow icon