如何在 y 系列上创建具有单个图例的折线图,而不是在 x 系列上显示多个图例
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<String> xs = XDDFDataSourcesFactory.fromStringCellRange(sheet, new CellRangeAddress(1, rows, 0, 0));
for (int col = 1; col < cols; col++) {
XDDFNumericalDataSource<Double> 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);
上图显示了我当前的绘图折线图,y 系列预计只有 1 个图例,但显示了多个
上图折线图是使用 Excel 绘制的,y 系列仅显示 1 个图例
翻过高山走不出你
相关分类