How to create chart in excel c#

@LongNgo,

Could you call Chart.Calculate() before evaluating DataLabels.Text value if it makes any difference.

Hi
I used code

                          for (int i = 0; i < series.Points.Count; i++)
                                {
                                    productsChartBDT.Calculate();
                                    string _str = series.Points[i].DataLabels.Text;
                                }

but _str is null

@LongNgo,

As percentage value (to be shown) on the chart is automatic so it won’t give you the data labels all the times. I think you may try the following workaround (you need to pick the source data in the cells and compare) to cope with your issue, see the following sample code. I have also attached the template file for your reference:
e.g
Sample code:

   Workbook workbook = new Workbook("e:\\test2\\Bk_datalabels1.xlsx");
    Worksheet worksheet = workbook.Worksheets[0];
    Chart chart = worksheet.Charts[0];

    chart.Calculate();

    Series series = chart.NSeries[0];
    string cellsArea = series.Values;

    Range range = worksheet.Cells.CreateRange(cellsArea);

     for (int i = range.FirstRow; i < range.RowCount + range.FirstRow; i++)
    {
       for (int j = range.FirstColumn; j < range.ColumnCount + range.FirstColumn; j++)
       {
        string _str = worksheet.Cells[i, j].StringValue;
        if (_str == "0") 
        {
            series.Points[i].DataLabels.ShowPercentage = false;
        }

        
       }
     }

     workbook.Save("e:\\test2\\out1.xlsx");

Hope, this helps a bit.
file1.zip (10.7 KB)

Thank you, Amjad_Sahi. This works for me

@LongNgo,

Good to know that the suggested code works for your needs. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.