How can I change charts generated by apache poi to not use smoothed lines and show empty cells as gaps?

后端 未结 2 1709
眼角桃花
眼角桃花 2021-01-20 14:00

I am using POI 3.12-beta1 and have code that creates a line chart with multiple datasets and named series in the legend. However, the default settings for line charts in poi

2条回答
  •  一生所求
    2021-01-20 14:27

    Thanks to Etienne for the code to set blanks as gaps. I got help from a POI developer and here is the solution that solves both issues mentioned in the original question.

        XSSFChart chart = (XSSFChart)drawing.createChart(anchor);
    
        // this will set blank values as gaps in the chart so you 
        // can accurately plot data series of different lengths
        CTDispBlanksAs disp = CTDispBlanksAs.Factory.newInstance();
        disp.setVal(STDispBlanksAs.GAP);
        chart.getCTChart().setDispBlanksAs(disp);
    
    
        // setup chart, axes, data series, etc
    
    
        chart.plot(data, new ChartAxis[] { bottomAxis, leftAxis });
    
        // this must occur after the call to chart.plot above
        CTPlotArea plotArea = chart.getCTChart().getPlotArea();
        for (CTLineChart ch : plotArea.getLineChartList()) {
            for (CTLineSer ser : ch.getSerList()) {
                CTBoolean ctBool = CTBoolean.Factory.newInstance();
                ctBool.setVal(false);
                ser.setSmooth(ctBool);
            }
        }
    

提交回复
热议问题