Hello,
Using the below code, I’ve created a combo chart with Bar and Line and enabled Axis titles for the primary and secondary value axis. Noticed two following issues.
- Both primary and secondary value axis titles are getting overlapped
- Both axis titles are getting displayed on the primary axis
Need help in fixing the overlap issues and updating the axis title text.
Generated ppt file: ComboChart-01.zip (35.1 KB)
The below code is used for creating the combo chart:
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);
// 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.getChartData().getSeries().get_Item(1).setPlotOnSecondAxis(true);
chart.getAxes().getSecondaryVerticalAxis().setPlotOrderReversed(true);
chart.getAxes().getSecondaryVerticalAxis().setTickLabelPosition(TickLabelPositionType.High);
chart.getAxes().getSecondaryVerticalAxis().setTitle(true);
pres.save(dataDir + "ComboChart-01.pptx", SaveFormat.Pptx);