我正在使用 POI 3.12-beta1,并拥有可创建包含多个数据集和图例中命名系列的折线图的代码。但是,poi 中折线图的默认设置会生成一条已在数据点上平滑的线。空值也被绘制为 0,但我们希望线条停在有空单元格的第一列。
在 xlsx 文件中呈现图表属性后,我可以进入图表属性并更改这些设置,但我们需要使用这些设置呈现 xlsx。我在可用的 API 中找不到任何可以更改这些设置的内容。
我使用这个示例类作为下面代码的起点http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java http://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 17, 18, 30);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.RIGHT);
LineChartData data = chart.getChartDataFactory().createLineChartData();
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
int row = 2;
int startCol = 3;
int endCol = 17;
boolean abs = false;
ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(row, row, startCol, endCol));
row = 10;
int seriesCol = 0;
ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(row, row, startCol, endCol));
LineChartSerie ser1 = data.addSerie(xs, ys1);
ser1.setTitle(new CellReference(sheet.getSheetName(), row, seriesCol, abs, abs));
row = 11;
ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(row, row, startCol, endCol));
LineChartSerie ser2 = data.addSerie(xs, ys2);
ser2.setTitle(new CellReference(sheet.getSheetName(), row, seriesCol, abs, abs));
row = 12;
ChartDataSource<Number> ys3 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(row, row, startCol, endCol));
LineChartSerie ser3 = data.addSerie(xs, ys3);
ser3.setTitle(new CellReference(sheet.getSheetName(), row, seriesCol, abs, abs));
chart.plot(data, new ChartAxis[] { bottomAxis, leftAxis });