开发者社区> 问答> 正文

POI 4.1.0 Line-Chart Y系列显示错误的图例

如何在y系列上创建带有单个图例的折线图,而不是在x系列上显示多个图例bease

int rows = numberOfRows - 1; int cols = headers.size();

XSSFDrawing drawing = sheet.createDrawingPatriarch(); XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15); XSSFChart chart = drawing.createChart(anchor); chart.displayBlanksAs(DisplayBlanks.GAP);

XDDFChartLegend legend = chart.getOrAddLegend(); legend.setPosition(LegendPosition.TOP_RIGHT);

// Use a category axis for the bottom axis. XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM); bottomAxis.setOrientation(AxisOrientation.MAX_MIN); bottomAxis.setTitle("Date");

XDDFValueAxis rightAxis = chart.createValueAxis(AxisPosition.RIGHT); rightAxis.setTitle("Rates"); rightAxis.setCrosses(AxisCrosses.AUTO_ZERO);

XDDFChartLegend chartLegend = chart.getOrAddLegend(); chartLegend.setPosition(LegendPosition.TOP_RIGHT); chartLegend.setOverlay(false);

XDDFLineChartData lineChartData = (XDDFLineChartData) chart.createData(ChartTypes.LINE, bottomAxis, rightAxis);

XDDFDataSource xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(1, rows, 0, 0));

for (int col = 1; col < cols; col++) { XDDFNumericalDataSource ys1 = XDDFDataSourcesFactory.fromNumericCellRange(sheet, new CellRangeAddress(1, rows, col, col)); XDDFLineChartData.Series series1 = (XDDFLineChartData.Series) lineChartData.addSeries(xs, ys1); series1.setTitle(headers.get(col), null); series1.setSmooth(false); series1.setMarkerStyle(MarkerStyle.NONE); }

chart.plot(lineChartData);

展开
收起
小六码奴 2019-10-12 16:46:23 1465 0
1 条回答
写回答
取消 提交回答
  • 在Excel2007之前,每个默认值都是false。现在Microsoft决定在默认情况下设置为true。所以如果你不想要的话,你需要明确地设置为false。 就你的情况而言: …

    xddflinechartdata linechartdata=(xddflinechartdata)chart.createData(charttypes.line,bottomaxis,rightaxis);

    linechartdata.setvarycolors(false);

    2019-10-12 16:51:01
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载