We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Creating Chart from range

Hi. I have founded that can’t create chart like i did it in Excel.


1) I have some range (3 columns). 1st column represents a category data (datetime), 2nd and 3rd - are data-columns.
2) In Excel i have created chart with range “A4:C18”. Click by “transparent” button and have received right chart with 2 series.

I tried to do this by code, but it failure - created chart have no datetime axisX type. It contains 3 sereis.

@Test
public void chartTest() {
try {
Workbook wb = new Workbook(“D:\chart.xls”);

Worksheet chartSheet = wb.getWorksheets().add(“TestChart”);

int idx = chartSheet.getCharts().add(ChartType.COLUMN, 5, 5, 20, 10);
Chart chart = chartSheet.getCharts().get(idx);
chart.getNSeries().add(“Данные!A4:C18”, true);

wb.save(“D:\out.xls”);

} catch (Exception e) {
e.printStackTrace();
assertNull(e);
}
}

Can you please explain me - how i can create chart by my range?

Best regards. Alexey

Hi Alexey,


Thank you for contacting Aspose support.

Please try the below provided code snippet on your end, and see if you get the desired chart.

Java

Workbook wb = new Workbook(myDir + “chart.xls”);
Worksheet chartSheet = wb.getWorksheets().add(“TestChart”);
int idx = chartSheet.getCharts().add(ChartType.COLUMN, 5, 5, 25, 15);
Chart chart = chartSheet.getCharts().get(idx);
//Set chart Series excluding the Category Data range
chart.getNSeries().add(“Данные!B4:C18”, true);
//Set Category Data range
chart.getNSeries().setCategoryData(“Данные!A4:A18”);
//Save results
wb.save(myDir + “out.xls”);

In case this is not what you are looking for then please provide your desired results, so we could review it and mimic the functionality using Aspose.Cells for Java API.