带有Apache POI的折线图-错误

时间:2018-07-16 09:06:56

标签: java excel charts apache-poi

我正在使用apache poi创建折线图,但是在编译期间没有NoClassDefFoundError。

XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("line chart");

Drawing<?> drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);

Chart chart = drawing.createChart(anchor);
((XSSFChart)chart).setTitleText("This is my title");

ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);

ChartDataSource<Integer> test = DataSources.fromArray(new Integer[]{2011,2012,2013,2014,2015,2016,2017});
ChartDataSource<Integer> test2 = DataSources.fromArray(new Integer[]{4805, 7351, 5333, 7183, 6230, 4050, 6963});

LineChartData data = chart.getChartDataFactory().createLineChartData();
data.addSeries(test, test2);

chart.plot(data, bottomAxis, leftAxis);
FileOutputStream outputStream = new FileOutputStream(FILE_NAME);
workbook.write(outputStream);

我发现问题出在ChartAxis和ValueAxis上,但我不知道出了什么问题以及如何解决。

Exception in thread "main" java.lang.NoClassDefFoundError: org/openxmlformats/schemas/drawingml/x2006/chart/CTCatAx
at org.openxmlformats.schemas.drawingml.x2006.chart.impl.CTPlotAreaImpl.addNewCatAx(Unknown Source)
at org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis.createAxis(XSSFCategoryAxis.java:120)
at org.apache.poi.xssf.usermodel.charts.XSSFCategoryAxis.<init>(XSSFCategoryAxis.java:51)
at org.apache.poi.xssf.usermodel.XSSFChart.createCategoryAxis(XSSFChart.java:217)
at org.apache.poi.xssf.usermodel.XSSFChart.createCategoryAxis(XSSFChart.java:71)
at pl.wasko.cassandrasucker.CassandraSuckerMain.main(CassandraSuckerMain.java:72)
Caused by: java.lang.ClassNotFoundException: org.openxmlformats.schemas.drawingml.x2006.chart.CTCatAx
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 6 more

0 个答案:

没有答案