Use own values instead of a sheet cells range

How can I use my own values as chart data?
For example, I have some values (10,20,30,40).
How can I use these values for a pie chart?
I don’t have a range of cells(as is in your examples).
Thank you !

Hi,


Thanks for your query.

Please see the sample code below for your needs for your reference:
e.g
Sample code:

//Create a new Workbook.
Workbook workbook = new Workbook();
//Add a chart sheet.
int sheetIndex = workbook.Worksheets.Add(SheetType.Chart);
Worksheet sheet = workbook.Worksheets[sheetIndex];
//Set the name of worksheet
sheet.Name = “Chart”;
//Create chart
int chartIndex = 0;
chartIndex = sheet.Charts.Add(ChartType.Pie, 1, 1, 25, 10);
Chart chart = sheet.Charts[chartIndex];
chart.NSeries.Add("{10,20,30,40}", true);
chart.NSeries.CategoryData = “{“sdf”,“sdf1”,“sdf2”, “sdf3”}”;
chart.NSeries.IsColorVaried = true;
//Set the DataLabels in the chart
DataLabels datalabels;
for (int i = 0; i < chart.NSeries.Count; i++)
{
datalabels = chart.NSeries[i].DataLabels;
datalabels.Position = LabelPositionType.InsideBase;
datalabels.ShowCategoryName = true;
datalabels.ShowPercentage = true;


}
//Save the excel file
workbook.Save(“e:\test2\out1.xlsx”);

Hope, this helps a bit.

Thank you.

Thank you !

Hi,


You are welcome! 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.

Thank you.