Hello, can you please advise me how I can read the data values used in a chart from the chart object?
Many thanks,
Sheridan
Hello, can you please advise me how I can read the data values used in a chart from the chart object?
Many thanks,
Sheridan
Thanks for your query.
Well, you may try to try to use: Series.Values attribute to get to know about the data source range of cells for the chart. Also, you will use Chart.NSeries.CategoryData attribute to get the category data range.
Hi Amjad,
it seems to me that you are advising me to find the data RANGE and the data SOURCE from the chart object, but not the chart DATA. Does that mean that the chart does not store the used data?
Well, you may try to use the suggested attributes and to know the series and category data range (e.g A2:B10, A1:B1, etc.). Now you may create a named range based on the data range string and browse through the range cells in the worksheet to get the actual data.
Hope, this helps a bit.
Thank you.
Can you please provide an example of how to find the actual data values using this named range that you mentioned?
See the following code segment for your reference:
e.g
Sample code:
Workbook workbook = new Workbook("e:\\test2\\Bk_howtocreate1.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;
}
}
.......
Hope, this helps a bit.
Thank you Amjad.
Now I understand what you mean.
Good to know that the suggested code is helpful to you. 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.