Hello,
I am using Aspose-Cells version 7.5.2
I am having troubles creating double value axis chart.
Currently code creates chart where Bar and Line chart are combined. I want bar chart to use secondary value axis and line chart use primary value axis.
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
//Adding a chart to the worksheet
ChartCollection charts = worksheet.getCharts();
//Accessing the instance of the newly added chart
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN,5,0,15,5);
Chart chart = worksheet.getCharts().get(chartIndex);
chart.getSecondValueAxis().setVisible(true);
//Adding NSeries (chart data source) to the chart ranging from “A1” cell to “B4”
SeriesCollection nSeries = chart.getNSeries();
int i1 = nSeries.add("{50, 100, 150, 300}",true);
Series columnsSeries = nSeries.get(i1);
columnsSeries.setPlotOnSecondAxis(true);
//Setting the chart type of 2nd NSeries to display as line chart
int i2 = nSeries.add("{60, 32, 50, 40}",true);
Series lineSeries = nSeries.get(i2);
lineSeries.getMarker().setMarkerStyle(ChartMarkerType.SQUARE);
lineSeries.getMarker().setMarkerSize(6);
lineSeries.setType(ChartType.LINE);
//Saving the Excel file
workbook.save(“C:\Users\VZ0715\Desktop\dest.pdf”, SaveFormat.PDF);
but when I am trying to do so I get exception:
Exception in thread “main” com.aspose.cells.CellsException: If there is only a series on the primary axis, you could not plot the series to the second axis
if I set line chart use secondary value axis and bar chart use primary value axis then I don’t get any exception.
//Instantiating a Workbook object
Workbook workbook = new Workbook();
//Obtaining the reference of the newly added worksheet
int sheetIndex = workbook.getWorksheets().add();
Worksheet worksheet = workbook.getWorksheets().get(sheetIndex);
Cells cells = worksheet.getCells();
//Adding a chart to the worksheet
ChartCollection charts = worksheet.getCharts();
//Accessing the instance of the newly added chart
int chartIndex = worksheet.getCharts().add(ChartType.COLUMN,5,0,15,5);
Chart chart = worksheet.getCharts().get(chartIndex);
chart.getSecondValueAxis().setVisible(true);
//Adding NSeries (chart data source) to the chart ranging from “A1” cell to “B4”
SeriesCollection nSeries = chart.getNSeries();
int i1 = nSeries.add("{50, 100, 150, 300}",true);
Series columnsSeries = nSeries.get(i1);
//Setting the chart type of 2nd NSeries to display as line chart
int i2 = nSeries.add("{60, 32, 50, 40}",true);
Series lineSeries = nSeries.get(i2);
lineSeries.getMarker().setMarkerStyle(ChartMarkerType.SQUARE);
lineSeries.getMarker().setMarkerSize(6);
lineSeries.setType(ChartType.LINE);
lineSeries.setPlotOnSecondAxis(true);
//Saving the Excel file
workbook.save(“C:\Users\VZ0715\Desktop\dest.pdf”, SaveFormat.PDF);
So how can I make bar chart to use secondary value axis and line chart use primary value axis without getting exception.
I’m trying to solve this issue 2 days already and it would be great some of your help.
Thanks
Kind Regards
Alikas