poi以及echarts 折线图空点跨越

 echarts:
   series: [
    {
      name: 'Email',
      type: 'line',
      stack: 'Total',
      data: [120, 132, 101, 134, 90, 230, 210],
      connectNulls:true  // 空点跨越
    }
    ]

POI  
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 26);
XSSFChart chart = (XSSFChart)drawing.createChart(anchor);
// 空点跨越
CTDispBlanksAs disp = CTDispBlanksAs.Factory.newInstance();
disp.setVal(STDispBlanksAs.GAP);
chart.getCTChart().setDispBlanksAs(disp);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以使用POI库来导出Excel折线图,并且可以设置线条为虚线。下面是一个示例代码,展示了如何使用POI来实现这个功能: ```java import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.*; import java.io.FileOutputStream; import java.io.IOException; public class ExcelChartExample { public static void main(String[] args) { // 创建一个新的Excel工作簿 Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("折线图示例"); // 创建一个数据源 Row row1 = sheet.createRow(0); row1.createCell(0).setCellValue(1); row1.createCell(1).setCellValue(2); row1.createCell(2).setCellValue(3); row1.createCell(3).setCellValue(4); Row row2 = sheet.createRow(1); row2.createCell(0).setCellValue(5); row2.createCell(1).setCellValue(6); row2.createCell(2).setCellValue(7); row2.createCell(3).setCellValue(8); // 创建一个折线图 Drawing drawing = sheet.createDrawingPatriarch(); ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 4, 0, 10, 20); Chart chart = drawing.createChart(anchor); ChartLegend legend = chart.getOrCreateLegend(); legend.setPosition(LegendPosition.BOTTOM); LineChartData data = chart.getChartDataFactory().createLineChartData(); // 创建折线 ChartAxis bottomAxis = chart.getChartAxisFactory().createCategoryAxis(AxisPosition.BOTTOM); ValueAxis leftAxis = chart.getChartAxisFactory().createValueAxis(AxisPosition.LEFT); leftAxis.setCrosses(AxisCrosses.AUTO_ZERO); ChartDataSource<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, 3)); ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, 3)); ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, 3)); LineChartSeries series1 = data.addSeries(xs, ys1); series1.setTitle(sheet.getRow(1).getCell(0).getStringCellValue()); LineChartSeries series2 = data.addSeries(xs, ys2); series2.setTitle(sheet.getRow(2).getCell(0).getStringCellValue()); // 设置线条样式为虚线 CTChartLines lines1 = series1.getCTLineSer().addNewSpPr().addNewLn().addNewPr(); lines1.addNewDash().setVal(new byte[]{4, 4}); CTChartLines lines2 = series2.getCTLineSer().addNewSpPr().addNewLn().addNewPr(); lines2.addNewDash().setVal(new byte[]{4, 4}); // 将图表添加到工作表 chart.plot(data, bottomAxis, leftAxis); // 保存Excel文件 try { FileOutputStream fileOut = new FileOutputStream("折线图示例.xlsx"); workbook.write(fileOut); fileOut.close(); workbook.close(); System.out.println("Excel文件导出成功!"); } catch (IOException e) { e.printStackTrace(); } } } ``` 这个示例代码会创建一个包含折线图的Excel文件,并且将线条样式设置为虚线。您可以根据需要修改数据源和线条样式的设置。请确保将POI添加到项目的依赖中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值