英文:
How to invert axis in Apache Poi
问题
以下是翻译好的内容:
我正在使用POI 4.1.0创建图表,但是我的柱状图颠倒了。
我如何翻转图表?
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, col2, row2);
XSSFChart chart = drawing.createChart(anchor);
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
XDDFDataSource<String> dataSource = XDDFDataSourcesFactory.fromStringCellRange(sheet,
new CellRangeAddress(startRow, data.getRows().size() + (startRow - 1), 0, 0));
XDDFChartData data = chart.createData(chartObj.getType(), bottomAxis, leftAxis);
XDDFNumericalDataSource<Double> values = XDDFDataSourcesFactory.fromNumericCellRange(sheet,
new CellRangeAddress(startRow, this.data.getRows().size() + (startRow - 1),
chartObj.getColumn(),chartObj.getColumn()));
XDDFChartData.Series series1 = data.addSeries(dataSource, values);
chart.plot(data);
英文:
I am using POI 4.1.0 to create charts but my bar chart is upside down
How can I flip the chart?
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, col2, row2);
XSSFChart chart = drawing.createChart(anchor);
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
leftAxis.setCrossBetween(AxisCrossBetween.BETWEEN);
XDDFDataSource<String> dataSource = XDDFDataSourcesFactory.fromStringCellRange(sheet,
new CellRangeAddress(startRow, data.getRows().size() + (startRow - 1), 0, 0));
XDDFChartData data = chart.createData(chartObj.getType(), bottomAxis, leftAxis);
XDDFNumericalDataSource<Double> values = XDDFDataSourcesFactory.fromNumericCellRange(sheet,
new CellRangeAddress(startRow, this.data.getRows().size() + (startRow - 1),
chartObj.getColumn(),chartObj.getColumn()));
XDDFChartData.Series series1 = data.addSeries(dataSource, values);
chart.plot(data);
答案1
得分: 1
XDDFChartData data = chart.createData(...);
...
XDDFBarChartData bar = (XDDFBarChartData) data;
bar.getCategoryAxis().setOrientation(AxisOrientation.MAX_MIN);
英文:
XDDFChartData data = chart.createData(...);
...
XDDFBarChartData bar = (XDDFBarChartData) data;
bar.getCategoryAxis().setOrientation(AxisOrientation.MAX_MIN);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论