如何从堆积条形图中删除未来日期

How to remove future dates from stacked-bar chart



代码示例

// line chart

// axis must be there but must not be visible
bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
bottomAxis.setVisible(false);
leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setVisible(false);

// set correct cross axis
bottomAxis.crossAxis(leftAxis);
leftAxis.crossAxis(bottomAxis);

data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
XDDFLineChartData.Series series4 = (XDDFLineChartData.Series)data.addSeries(date, category);
series4.setTitle("Total", null);
series4.setSmooth(false);
series4.setMarkerStyle(MarkerStyle.STAR);
chart.plot(data);

// correct the id and order, must not start 0 again because there are three bar series already
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getIdx().setVal(3);
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getOrder().setVal(3);

solidLineSeries(data, 0, PresetColor.YELLOW);

// add data labels
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).addNewDLbls();
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls()
 .addNewSpPr().addNewSolidFill().addNewSrgbClr().setVal(new byte[]{(byte)255,(byte)255,0});
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls()
 .addNewDLblPos().setVal(org.openxmlformats.schemas.drawingml.x2006.chart.STDLblPos.CTR);
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowVal().setVal(true);
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(false);
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowCatName().setVal(false);
chart.getCTChart().getPlotArea().getLineChartArray(0).getSerArray(0).getDLbls().addNewShowSerName().setVal(false);
  • 首先你必须在 chart.plot(data);.

    之前编写以下代码行

    这会将空白值设置为图表中的间隙,以便您可以准确绘制不同长度的数据系列

CTDispBlanksAs disp = CTDispBlanksAs.Factory.newInstance();    
disp.setVal(STDispBlanksAs.GAP);    
chart.getCTChart().setDispBlanksAs(disp);    
  • 进口
import org.openxmlformats.schemas.drawingml.x2006.chart.CTDispBlanksAs;    
import org.openxmlformats.schemas.drawingml.x2006.chart.STDispBlanksAs;
  • 然后在绘制代码和外部循环之后,编写代码将这些零设置为空白。
int rownum = 0;      
// loop start     
Row rowT = sheetTestcasenBurndown.getRow(rownum);    
for (int cellnumStart = 1; cellnumStart <= cellnumEnd; cellnumStart++) {     
    Cell cell = rowT.getCell(cellnumStart);       
    cell.setCellType(CellType.BLANK);    
}    
// loop end     
rownum++;

Output