I am trying to create a combo chart. I have done setPlotOnSecondAxis as TRUE for the second series but I am not able to get the right output i.e. both the axis are coming on left side.
Note: Chart type is ClusteredColumn
Thanks in advance
Output file: ComboChart-01.zip (34.0 KB)
Please refer to this code and let me know what I’m doing wrong :
Presentation pres = new Presentation();
IChart chart = pres.getSlides().get_Item(0).getShapes().addChart(ChartType.ClusteredColumn, 50, 50, 600, 400);
chart.getChartTitle().addTextFrameForOverriding("Chart Title");
chart.getChartTitle().setHeight(20);
chart.getChartTitle().setOverlay(false);
chart.setTitle(true);
chart.getLegend().setPosition(LegendPositionType.Bottom);
chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(12);
// Setting the index of the chart data sheet
final int defaultWorksheetIndex = 0;
// Getting the chart data worksheet
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook();
// Delete default generated series and categories
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
// Adding new categories
chart.getChartData().getCategories().add(fact.getCell(0, 1, 0, "Jan"));
chart.getChartData().getCategories().add(fact.getCell(0, 2, 0, "Feb"));
chart.getChartData().getCategories().add(fact.getCell(0, 3, 0, "Mar"));
chart.getChartData().getCategories().add(fact.getCell(0, 4, 0, "Apr"));
chart.getChartData().getCategories().add(fact.getCell(0, 5, 0, "May"));
// Adding new series
IChartSeries series = chart.getChartData().getSeries().add(fact.getCell(0, 0, 1, "Total Revenue"), ChartType.ClusteredColumn);
// Now populating series data
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 34.912));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 21.919));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 49.198));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 4, 1, 45.214));
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 5, 1, 26.871));
// Adding new series
IChartSeries series1 = chart.getChartData().getSeries().add(fact.getCell(0, 0, 2, "Price 2020"), ChartType.Line);
series1.setPlotOnSecondAxis(true);
// Now populating series data
series1.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 10.312));
series1.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 9.272));
series1.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 12.696));
series1.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 4, 2, 11.313));
series1.getDataPoints().addDataPointForLineSeries(fact.getCell(defaultWorksheetIndex, 5, 2, 11.379));
chart.getAxes().getVerticalAxis().setTitle(true);
chart.getAxes().getVerticalAxis().getTitle().addTextFrameForOverriding("Axis 1");
chart.getAxes().getVerticalAxis().getTitle().setOverlay(false);
chart.getAxes().getSecondaryVerticalAxis().setTitle(true);
chart.getAxes().getSecondaryVerticalAxis().getTitle().addTextFrameForOverriding("Axis 2");
chart.getAxes().getSecondaryVerticalAxis().getTitle().setOverlay(false);
chart.getAxes().getHorizontalAxis().setVisible(false);
pres.save("ComboChart-01.pptx", SaveFormat.Pptx);