Hi,
I am adding a chart and want to set it’s data without the need to work with external worksheets. It seems that the addChart
method creates some sample data. If the number of categories/series of my data does not match that of the sample data, how do I change the dimensions of the data? The only method I found is the IChartData.setRange
method, but that requires a sheet name. I just guessed “Sheet1” for the sheet name from the sample code at https://github.com/Muhammad-Adnan-Ahmad/Aspose.Slides-for-Java, using a range of "Sheet1!$A$1:$D$4"
. But this is not documented anywhere, nor do I find a method to read the sheets from the internal worksheet or e. g. an IChartData.getRange
method.
Can I be sure the name of the sheet for all charts I create using Aspose.Slides, even if I create many charts in a presentation, and on different operating systems with different operating system languages, is always “Sheet1”?
Here is the sample code I used for testing:
IChart chart = slide.getShapes().addChart(ChartType.StackedColumn, 50, 100, 500, 380);
IChartDataWorkbook wb = chart.getChartData().getChartDataWorkbook();
wb.clear(0);
wb.getCell(0, 0, 1).setValue(“A”);
wb.getCell(0, 0, 2).setValue(“B”);
wb.getCell(0, 0, 3).setValue(“C”);
wb.getCell(0, 1, 0).setValue(“2018”);
wb.getCell(0, 1, 1).setValue(10);
wb.getCell(0, 1, 2).setValue(13);
wb.getCell(0, 1, 3).setValue(16);
wb.getCell(0, 2, 0).setValue(“2019”);
wb.getCell(0, 2, 1).setValue(3);
wb.getCell(0, 2, 2).setValue(20);
wb.getCell(0, 2, 3).setValue(7);
wb.getCell(0, 3, 0).setValue(“2020”);
wb.getCell(0, 3, 1).setValue(15);
wb.getCell(0, 3, 2).setValue(6);
wb.getCell(0, 3, 3).setValue(12);
chart.getChartData().setRange(“Sheet1!$A$1:$D$4”); // “Sheet1” is just a guess
setSeriesColor(chart,0, new Color(200, 0, 0));
setSeriesColor(chart,1, new Color(0, 200, 0));
setSeriesColor(chart,2, new Color(0, 0, 200));