效果

代码

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.usermodel.charts.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.FileOutputStream;public class LineChartDemo {public static void main(String[] args) throws Exception {Workbook wb = new XSSFWorkbook();Sheet sheet = wb.createSheet("linechart");final int NUM_OF_ROWS = 3;final int NUM_OF_COLUMNS = 10;// Create a row and put some cells in it. Rows are 0 based.Row row;Cell cell;for (int rowIndex = 0; rowIndex < NUM_OF_ROWS; rowIndex++) {row = sheet.createRow((short) rowIndex);for (int colIndex = 0; colIndex < NUM_OF_COLUMNS; colIndex++) {cell = row.createCell((short) colIndex);cell.setCellValue(colIndex * (rowIndex + 1));}}Drawing drawing = sheet.createDrawingPatriarch();ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, 0, 5, 10, 15);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<Number> xs = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(0, 0, 0, NUM_OF_COLUMNS - 1));ChartDataSource<Number> ys1 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(1, 1, 0, NUM_OF_COLUMNS - 1));ChartDataSource<Number> ys2 = DataSources.fromNumericCellRange(sheet, new CellRangeAddress(2, 2, 0, NUM_OF_COLUMNS - 1));LineChartSeries lineChartSeries1 = data.addSeries(xs, ys1);LineChartSeries lineChartSeries2 = data.addSeries(xs, ys2);//设置图例lineChartSeries1.setTitle("加多宝");lineChartSeries2.setTitle("王老吉");chart.plot(data, bottomAxis, leftAxis);// Write the output to a fileFileOutputStream fileOut = new FileOutputStream("D://line_demo.xlsx");wb.write(fileOut);fileOut.close();}
}

poi在Excel中创建折线图相关推荐

  1. java利用POI在word中绘制折线图

    1.poi的简介 Apache POI 简介是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office(Excel.WORD ...

  2. excel瀑布图_在Excel中创建瀑布图

    excel瀑布图 We have a very famous waterfall here in Canada, and it creates gorgeous photos, like this o ...

  3. java实现条形图_java – 使用Apache POI在Excel中创建条形图

    P,很难生;-).对于不了解背景 Apache POI supports only ScatterCharts and LineCharts why?的用户.描述了原则上如何进行. 就像我说的.用最简 ...

  4. python在excel中插入折线图_python如何删除excel中已经存在的折线图?

    通过excel复制,重新生成一个新的excel实现: import copy import openpyxl from openpyxl.utils import get_column_letter ...

  5. 如何在Excel中创建一个折线图?

    poi官方文档地址 参考资料 参考了其他人的写法,加入了我自己的一些注释,额外加了几个方法. @Testvoid chartTest() throws IOException {Workbook wb ...

  6. 使用POI在Excel中动态生成图表工具类(支持柱状、组合、环状图、折线图、等常用图)

    使用POI在Excel中动态生成图表工具类 使用POI在Excel中动态生成图表工具类 由于公司是一个生成报表的机构,之前一直使用pageOffice,但是公司领导就是不买,你说公司那样有钱磨磨唧唧干 ...

  7. excel分析图表制作,如何轻松创建折线图、柱状图、饼图

    ​在Excel中通过数据间的关系选择合适的图表,轻松创建折线图.柱状图.饼图使其表达的主题和内容更加简单清晰. 下面我们通过Smartbi大数据分析工具介绍excel分析图表制作方法,如何制作常用的图 ...

  8. 青蛙换位置excel_吃青蛙:如何在Excel中创建每日交付的sprint消耗图

    青蛙换位置excel In the first article I wrote on how to create a SCRUM-based, sprint burn down in Excel, H ...

  9. 创建jira sprint_如何在Excel中创建高级sprint燃尽图

    创建jira sprint SCRUM is a great way to manage all sorts of tasks including sprints, but you don't hav ...

  10. excel箱形图中位数_在Excel中创建简单的箱形图

    excel箱形图中位数 A box plot (box and whisker chart) lets you show how numbers are distributed in a set of ...

最新文章

  1. router OS (ROS)命令中文手册
  2. 为什么Java的main方法必须是public static void?
  3. 【转载】WINCE物理和虚拟地址的问题
  4. VTK:Utilities之LUTUtilities
  5. vim 代码注释插件
  6. Spark内置图像数据源初探
  7. Qt工作笔记-Qt生成dll或so,并且调用(含Liunx端与Windows端)
  8. 鸿蒙系统存储空间,鸿蒙系统即将上线!看到内存要求后,网友:逼我换手机?...
  9. python矩阵所有元素取整_Python中如何对一个数值进行取整操作呢?
  10. LCM模组的简介与质量管理(连载四)
  11. matlab 求平面方程,MATLAB求空间平面方程
  12. 云计算 | Centos7和Ubuntu1804制作本地安装源
  13. 摄氏温度转化为华氏温度代码
  14. 搭建微信多开服务器,电脑微信多开你都不会?教你简单实现
  15. gif动图怎么制作?gif动图制作教程大全
  16. EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT
  17. java.util包
  18. Unity实现AR扫描图片
  19. 贪心算法-磁带最优存储问题
  20. 计算机应用基础张宇答案,计算机应用基础电子教案教学课件作者张宇单选课件.doc...

热门文章

  1. 快捷方式图标变成白色
  2. 中国科技网宽带接入服务
  3. python中pow_Python中float的内置pow()和math.pow()之间的区别?
  4. 微信小程序高德地图获取当前定位
  5. 如何规避采购风险?五种有效的采购风险防范措施
  6. Linux下vasp优化结构,VASP入门系列文章[6]结构优化
  7. ISE WARNING:ProjectMgmt - File /*filePath*/ is missing.解决方法
  8. 操作系统的分段与逻辑地址和转换物理地址
  9. 为什么P2P模式下载的人越多速度越快,为什么P2P伤害机械硬盘
  10. 谱尼又一子公司获批成为化妆品人体安全性和功效评价检验注册备案机构