jar
compile('org.apache.poi:poi:4.0.1')
compile('org.apache.poi:poi-scratchpad:4.0.1')
compile('org.apache.poi:poi-ooxml:4.0.1')
compile('org.apache.poi:ooxml-schemas:1.4') public static class Inbound_chartExport{
public XSSFSheet sheet;//操作的sheet
public String title;//头部标题
public String seriesTitle;//系列标题
public String xName;//x轴标题
public String yName;
public int startRow;//开始行数
public int size;//结束行数
public int xStartCol;//x轴列数
public int yStartCol;
public int col1;//图标放置位置
public int row1;
public int col2;
public int row2;
}
public void excelBarChart(Inbounds.Inbound_chartExport inbound){
XSSFDrawing drawing = inbound.sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, inbound.col1, inbound.row1, inbound.col2, inbound.row2); XSSFChart chart = drawing.createChart(anchor);//图表
chart.setTitleText(inbound.title);
chart.setTitleOverlay(false);
XDDFChartLegend legend = chart.getOrAddLegend();//图例项
legend.setPosition(LegendPosition.TOP_RIGHT); // Use a category axis for the bottom axis.
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);//x轴和位置
bottomAxis.setTitle(inbound.xName);
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);//y轴和位置
leftAxis.setTitle(inbound.yName);
leftAxis.setCrosses(AxisCrosses.AUTO_ZERO);
XDDFChartData data = chart.createData(ChartTypes.BAR, bottomAxis, leftAxis);//生成Data XDDFDataSource<String> xs = XDDFDataSourcesFactory.fromStringCellRange(inbound.sheet, new CellRangeAddress(inbound.startRow, inbound.size, inbound.xStartCol, inbound.xStartCol));//x轴range区域
XDDFNumericalDataSource<Double> ys1 = XDDFDataSourcesFactory.fromNumericCellRange(inbound.sheet, new CellRangeAddress(inbound.startRow, inbound.size, inbound.yStartCol, inbound.yStartCol));//y轴range区域
XDDFChartData.Series series1 = data.addSeries(xs, ys1);//生成Series 系列/维度
series1.setTitle(inbound.seriesTitle, null); chart.plot(data);
XDDFBarChartData bar = (XDDFBarChartData) data;//由数据生成图表,Bar柱状图,Pie饼状图,Line折线图,Scatter散点图
bar.setBarDirection(BarDirection.BAR);//柱状如方向 BAR 竖向 COL横向 CTChart ctChart = chart.getCTChart();
CTPlotArea ctPlotArea = ctChart.getPlotArea();
CTBarChart ctBarChart = ctPlotArea.getBarChartArray(0);
CTBarSer ctBarSer = ctBarChart.getSerArray(0);
CTDLbls newDLbls = ctBarSer.addNewDLbls();//数据标签
CTBoolean ctBoolean = ctBarChart.addNewVaryColors();//多样颜色,true 选用category作为图例项,false选用系列作为图例项,最好false
ctBoolean.setVal(false);
newDLbls.setShowCatName(ctBoolean);//数据标签 显示类别名称
newDLbls.setShowSerName(ctBoolean);//数据标签 显示序列名称
newDLbls.setShowPercent(ctBoolean);
newDLbls.setShowBubbleSize(ctBoolean);
newDLbls.setShowLeaderLines(ctBoolean);
newDLbls.setShowLegendKey(ctBoolean);//图例化标签
newDLbls.addNewShowVal().setVal(true);//数据标签 显示值 solidFillSeries(data, 0, PresetColor.CHARTREUSE);//颜色PresetColor
}
private static void solidFillSeries(XDDFChartData data, int index, PresetColor color) {
XDDFSolidFillProperties fill = new XDDFSolidFillProperties(XDDFColor.from(color));
XDDFChartData.Series series = data.getSeries().get(index);
XDDFShapeProperties properties = series.getShapeProperties();
if (properties == null) {
properties = new XDDFShapeProperties();
}
properties.setFillProperties(fill);
series.setShapeProperties(properties);
}

Excel导出(Java)资料
柱状图(poi 3.17):https://stackoverflow.com/questions/38913412/create-bar-chart-in-excel-with-apache-poi
饼图(poi 3.17):https://stackoverflow.com/questions/34718734/apache-poi-supports-only-scattercharts-and-linecharts-why
利用导入的模板导出(poi 3.17之前):https://blog.cacoveanu.com/2015/2015.08.27.15.15.charts.apache.poi.html
poi 4.0.1chart(Example):https://svn.apache.org/repos/asf/poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/
官方文档:https://poi.apache.org/apidocs/dev/org/apache/poi/xddf/usermodel/chart/package-summary.html
中文事例:https://blog.csdn.net/qq_24365145/article/details/89146549
https://blog.csdn.net/Lonely_boy_/article/details/88870079

Java利用Apache poi导出图表的更多相关文章

  1. java 通过Apache poi导出excel代码demo实例

    package com.zuidaima.excel.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutput ...

  2. Java利用Apache POI将数据库数据导出为excel

    将数据库中的数据导出为excel文件,供其他人查看 public class POITest { public static void main(String[] args) { POITest te ...

  3. 使用Apache POI导出Excel小结--导出XLS格式文档

    使用Apache POI导出Excel小结 关于使用Apache POI导出Excel我大概会分三篇文章去写 使用Apache POI导出Excel小结--导出XLS格式文档 使用Apache POI ...

  4. Read / Write Excel file in Java using Apache POI

    Read / Write Excel file in Java using Apache POI 2014-04-18 BY DINESH LEAVE A COMMENT About a year o ...

  5. 利用Apache POI 实现简单的Excel表格导出

    1.利用POI API实现简单的Excel表格导出 首先假设一个学生实体类: package com.sun.poi.domain; import java.io.Serializable; impo ...

  6. Java使用Apache POI进行Excel导入和导出

    Manve依赖 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> ...

  7. apache poi导出excel报表

    Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写的功能.POI为"P ...

  8. java中使用poi导出excel表格数据并且可以手动修改导出路径

    在我们开发项目中,很多时候会提出这样的需求:将前端的某某数据以excel表格导出,今天就给大家写一个简单的模板. 这里我们选择使用poi导出excel: 第一步:导入需要的jar包到 lib 文件夹下

  9. Java中用Apache POI生成excel和word文档

    概述: 近期在做项目的过程中遇到了excel的数据导出和word的图文表报告的导出功能.最后决定用Apache POI来完毕该项功能.本文就项目实现过程中的一些思路与代码与大家共享.同一时候.也作为自 ...

随机推荐

  1. ThinkPHP 添加数据到数据库失败

    ThinkPHP 添加数据到数据库失败 一般情况下会先检查一下几个方面 检查控制器或Model名是否有误 检查需要插入的数据是否为空或者缺失参数 检查数据表名及字段名称(大部分下都是字段名有误出错的) ...

  2. 神奇的 SQL 之 CASE表达式,妙用多多 !

    前言 历史考试选择题:黄花岗起义第一枪谁开的? A宋教仁 B孙中山 C黄兴 D徐锡麟,考生选C. 又看第二题:黄花岗起义第二枪谁开的? 考生傻了,就选了个B. 接着看第三题:黄花岗起义中,第三枪谁开的 ...

  3. (11)ASP.NET Core 中的配置一(Configuration)

    1.前言 ASP.NET Core在应用程序上引入Microsoft.Extensions.Configuration配置,可以支持多种方式配置,包括命令行配置.环境变量配置.文件配置.内存配置,自定 ...

  4. HTML&CSS兼容性总结

    对目前所遇见的兼容性笔记进行整理分类: 不兼容浏览器 问题概要 问题描述 解决方法 IE6,IE7  3px 并列一行的元素左侧第一个元素没浮动,第二个元素左浮动,则两个元素之间会多3像素空隙 并在一 ...

  5. 0 ElasticSearch

    注意事项 需要jdk环境1.7以上 Elasticsearch Kibana 的下载地址统一为https://www.elastic.co/downloads/ 问题排查可以登录https://dis ...

  6. some (1)

    每次在写博客的时候,都是自己觉得在工作中非常重要的东西,写东西的时候,也是一个思考的过程.好的东西不光帮助别人,也使自己有进一步的理解.

  7. 【Java】Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 1099

    详细信息如下: Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: ...

  8. html+css+dom补充

    补充1:页面布局 一般像京东主页左侧右侧都留有空白,用margin:0 auto居中,一般.w. <!DOCTYPE html> <html lang="en"& ...

  9. redis分布式锁&队列应用

    分布式锁 setnx(set if not exists) 如果设值成功则证明上锁成功,然后再调用del指令释放. // 这里的冒号:就是一个普通的字符,没特别含义,它可以是任意其它字符,不要误解 & ...

  10. UR机器人的位姿

    一.Ur 移动命令 UR机器人移动,一共有三种移动指令,movej,movel,movep,分别是关节运动,线性运动,圆周运动. movej:6个关节的弧度 movel/movep:分别是x,y,z, ...