Pau*_*nis 9 java excel charts apache-poi
我在Excel文档中使用Apache POI创建了一个LineChart.至于我设法实现的是在下面的图像:

我使用Apache的svn中的示例编写了代码,因此我当前的方法如下所示:
Drawing drawing = question.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 4, 8, 14, 18);
Chart chart = drawing.createChart(anchor);
ChartLegend legend = chart.getOrCreateLegend();
legend.setPosition(LegendPosition.TOP_RIGHT);
LineChartData data = chart.getChartDataFactory().createLineChartData();
ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM);
bottomAxis.setCrosses(AxisCrosses.AUTO_ZERO);
ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
List<ReportQuestionModel> questionModels = groupModel.getQuestionModels();
for (ReportQuestionModel questionModel : questionModels) {
List<ReportOptionModel> optionModels = questionModel.getOptionModels();
for (ReportOptionModel optionModel : optionModels) {
rowNum++;
XSSFRow optionRow = question.createRow(rowNum);
XSSFCell optionsCell = optionRow.createCell(0);
optionsCell.setCellValue(optionModel.getAnswerText());
long count = optionModel.getCount();
totalResponses += count;
XSSFCell optionsCountCell = optionRow.createCell(1);
optionsCountCell.setCellValue(count);
XSSFCell optionsPercentageCell = optionRow.createCell(2);
optionsPercentageCell.setCellValue(optionModel.getPercentage());
}
}
ChartDataSource<Number> xs = DataSources.fromNumericCellRange(question, new CellRangeAddress(8, 8, 0, 1));
for (int i = 9; i <= rowNum; i ++) {
ChartDataSource<Number> ys = DataSources.fromNumericCellRange(question, new CellRangeAddress(i, i, 0, 1));
data.addSerie(xs, ys);
}
chart.plot(data, bottomAxis, leftAxis);
Run Code Online (Sandbox Code Playgroud)
我找不到的是如何"Series 1", "Series 2", ..., "Series n"从列中获取默认名称作为我的值,在这种情况下来自:"答案选项".并且在当前API中似乎没有任何方法如何指定系列的名称.
请问有人帮我吗?
Pau*_*nis 15
它非常直接,而不是使用:
data.addSeries(xs, ys);
Run Code Online (Sandbox Code Playgroud)
我不得不使用:
LineChartSeries chartSeries = data.addSeries(xs, ys);
chartSeries.setTitle("My Title");
Run Code Online (Sandbox Code Playgroud)
没有查看使用data.addSeries(xs, ys);返回单个LineChartSeries对象的API,我可以在其上设置标题.
| 归档时间: |
|
| 查看次数: |
5539 次 |
| 最近记录: |