How can I set only the plot area height in XSSFChart using Apache POI 4.1.2

369 Views Asked by At

I have created a stacked bar chart using a template file. In my chart, there is one series and more than 100 legends. To show all legends I have adjusted the plot area Y-axis value, now the bar size bigger than expected. Are there any methods to adjust the Plot area height? Sample

         int additionalRows = barCount * barSize;
         additionalRows = additionalRows + (addressList.size()/3);
         chart = graphSheet.createDrawingPatriarch().createChart(new XSSFClientAnchor(100, 100, 100, 100, 1, currentIndex, 2, currentIndex+= additionalRows));
         XSSFChart stackedFullBarChart = templateSheet.getDrawingPatriarch().getCharts().get(ChartType.STACKED_FULL_CHART.getValue());
         chart.importContent(stackedFullBarChart);

         chart.setTitleText(title);
         XDDFChartData chartData = chart.getChartSeries().get(0);
         XDDFDataSource<?> category = XDDFDataSourcesFactory.fromStringCellRange(dataSheet, categoryCells);
         for (int i = 0; i < addressList.size(); i++) {
            XDDFNumericalDataSource<?> values = XDDFDataSourcesFactory.fromNumericCellRange(dataSheet, addressList.get(i));
            int seriesNameRow = addressList.get(i).getFirstRow() - 2;
            int seriesNameCol = addressList.get(i).getFirstColumn();
            XSSFCell seriesNameCell = dataSheet.getRow(seriesNameRow).getCell(seriesNameCol);
            String seriesName = seriesNameCell.getStringCellValue();
            if (i >= chartData.getSeriesCount()) {
                XDDFChartData.Series series1 = chartData.addSeries(category, values);
                series1.setTitle(seriesName, new CellReference(seriesNameCell));
            } else {
                chartData.getSeries(i).setTitle(seriesName, new CellReference(seriesNameCell));
                chartData.getSeries(i).replaceData(category, values);
            }
        }
        chart.getOrAddManualLayout().setWidthRatio(0.8);
        **chart.getOrAddManualLayout().setHeightRatio(0.9);
        chart.getOrAddManualLayout().setY(1.1);**
        chart.plot(chartData);

        chart.getOrAddLegend().setPosition(LegendPosition.TOP);
        CTLegend ctLegend = chart.getCTChart().addNewLegend();
        ctLegend.addNewLegendPos().setVal(STLegendPos.T);
        CTBoolean ctBoolean = CTBoolean.Factory.newInstance();
        ctBoolean.setVal(false);
        ctLegend.setOverlay(ctBoolean);
        CTDouble ctdouble = CTDouble.Factory.newInstance();
        ctdouble.setVal(0.1);
        chart.getCTChart().getPlotArea().getLayout().getManualLayout().setH(ctdouble);

Expected Output:

Expected Output

0

There are 0 best solutions below