有问题official例子折线图 and 散点图适用于 Apache POI 4.0。它们编译并运行没有错误,但创建的Excel文件无法打开,提示有不可读的内容。 Excel 2010 和 2016 提供了从工作簿恢复数据的选项,单击“是”后,此dialog出现。可能是什么问题?
The new XDDF
代码缺少设置axId
是在lineChart
and scatterChart
.
In /xl/charts/chart1.xml
这看起来像:
<c:lineChart>
...
<c:axId val="0"/>
<c:axId val="1"/>
</c:lineChart>
对于折线图..
添加:
...
XDDFChartData data = chart.createData(ChartTypes.LINE, bottomAxis, leftAxis);
data.addSeries(xs, ys1);
data.addSeries(xs, ys2);
chart.plot(data);
//setting the axis Ids to the LineChart
chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(bottomAxis.getId());
chart.getCTChart().getPlotArea().getLineChartArray(0).addNewAxId().setVal(leftAxis.getId());
// Write the output to a file
try (FileOutputStream fileOut = new FileOutputStream("ooxml-line-chart.xlsx")) {
wb.write(fileOut);
}
...
in LineChart.java
and
...
XDDFChartData data = chart.createData(ChartTypes.SCATTER, bottomAxis, leftAxis);
data.addSeries(xs, ys1);
data.addSeries(xs, ys2);
chart.plot(data);
//setting the axis Ids to the ScatterChart
chart.getCTChart().getPlotArea().getScatterChartArray(0).addNewAxId().setVal(bottomAxis.getId());
chart.getCTChart().getPlotArea().getScatterChartArray(0).addNewAxId().setVal(leftAxis.getId());
// Write the output to a file
try (FileOutputStream fileOut = new FileOutputStream("ooxml-scatter-chart.xlsx")) {
wb.write(fileOut);
}
...
in ScatterChart.java
它会起作用的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)