如何在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);
在Excel2007之前,每个默认值都是false。现在Microsoft决定在默认情况下设置为true。所以如果你不想要的话,你需要明确地设置为false。 就你的情况而言: …
xddflinechartdata linechartdata=(xddflinechartdata)chart.createData(charttypes.line,bottomaxis,rightaxis);
linechartdata.setvarycolors(false);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。