java excle生成统计图

时间:2023-08-08 11:50:45
【文件属性】:

文件名称:java excle生成统计图

文件大小:11KB

文件格式:PNG

更新时间:2023-08-08 11:50:45

java

Workbook wb = new XSSFWorkbook(); Sheet sheet1 = wb.createSheet("统计图"); /** *往sheet1添加数据 */ Drawing drawing = sheet1.createDrawingPatriarch(); ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 9, 10, 19); // Chart chart = drawing.createChart(anchor); ChartLegend legend = chart.getOrCreateLegend(); legend.setPosition(LegendPosition.TOP_RIGHT); LineChartData data = chart.getChartDataFactory().createLineChartData(); // Use a category axis for the bottom axis. ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM); ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT); leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); /** *生成统计图的重要部分,从表格的那个地方开始到那个地方结束 */ ChartDataSource xs = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(2, 7, 1, 1)); ChartDataSource xs1 = DataSources.fromNumericCellRange(sheet1, new CellRangeAddress(2, 7, 0, 0)); data.addSerie(xs1, xs); chart.plot(data, bottomAxis, leftAxis);


网友评论