Java利用Apache poi导出图表
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导出图表的更多相关文章
- java 通过Apache poi导出excel代码demo实例
package com.zuidaima.excel.util; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutput ...
- Java利用Apache POI将数据库数据导出为excel
将数据库中的数据导出为excel文件,供其他人查看 public class POITest { public static void main(String[] args) { POITest te ...
- 使用Apache POI导出Excel小结--导出XLS格式文档
使用Apache POI导出Excel小结 关于使用Apache POI导出Excel我大概会分三篇文章去写 使用Apache POI导出Excel小结--导出XLS格式文档 使用Apache POI ...
- 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 ...
- 利用Apache POI 实现简单的Excel表格导出
1.利用POI API实现简单的Excel表格导出 首先假设一个学生实体类: package com.sun.poi.domain; import java.io.Serializable; impo ...
- Java使用Apache POI进行Excel导入和导出
Manve依赖 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml --> <dependency> ...
- apache poi导出excel报表
Apache POI 是用Java编写的免费开源的跨平台的 Java API,Apache POI提供API给Java程式对Microsoft Office格式档案读和写的功能.POI为"P ...
- java中使用poi导出excel表格数据并且可以手动修改导出路径
在我们开发项目中,很多时候会提出这样的需求:将前端的某某数据以excel表格导出,今天就给大家写一个简单的模板. 这里我们选择使用poi导出excel: 第一步:导入需要的jar包到 lib 文件夹下
- Java中用Apache POI生成excel和word文档
概述: 近期在做项目的过程中遇到了excel的数据导出和word的图文表报告的导出功能.最后决定用Apache POI来完毕该项功能.本文就项目实现过程中的一些思路与代码与大家共享.同一时候.也作为自 ...
随机推荐
- [Abp vNext 源码分析] - 6. DDD 的应用层支持 (应用服务)
一.简要介绍 ABP vNext 针对于应用服务层,为我们单独设计了一个模块进行实现,即 Volo.Abp.Ddd.Application 模块. PS:最近博主也是在恶补 DDD 相关的知识,这里推 ...
- arm汇编指令--str ldr
STR :把寄存器中的字保存到存储器(寄存器到存储器) 示例: STR R0,[R1],#8 :将R0中的字数据写入以R1为地址的存储器中,并将新地址R1+8写入R1.STR ...
- [机器学习] kears入门:用单层网络实现玩具回归
learn from: 莫烦教keras的视频: https://morvanzhou.github.io/tutorials/machine-learning/keras/2-1-regressor ...
- Mybatis连接查询返回类型问题
一对一映射 public class Card { private Integer id; private String num; private Student student; //重要 publ ...
- python利用select实现的Socket Server
# 利用python的select模块实现简单的Socket Sever #实现多用户访问,再次基础上可以实现FTP Server应用程序 # 发布目的,在于解决了客户端强行终止时,服务器端也跟着程序 ...
- IT技术管理者的自我修养
1. 前言 本来写<IT技术管理者的自我修养>与<IT技术人员的自我修养>是一开始就有的想法.但发表<IT技术人员的自我修养>后,收到了不少良好的反馈,博客园的编辑 ...
- abp(net core)+easyui+efcore实现仓储管理系统目录
abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...
- 【网站公告】.NET Core 版博客站点第二次发布尝试
在上次发布失败后,很多朋友建议我们改用 k8s ,但我们还是想再试试 docker swarm ,实在不行再改用 k8s . 在改进了 docker swarm 集群的部署后,我们准备今天 17:30 ...
- 逆向破解之160个CrackMe —— 001
CrackMe —— 001 160 CrackMe 是比较适合新手学习逆向破解的CrackMe的一个集合一共160个待逆向破解的程序 CrackMe:它们都是一些公开给别人尝试破解的小程序,制作 c ...
- GDOI#348大陆争霸[SDOI2010]最短路有限制条件
在一个遥远的世界里有两个国家:位于大陆西端的杰森国和位于大陆东端的 克里斯国.两个国家的人民分别信仰两个对立的神:杰森国信仰象征黑暗和毁灭 的神曾·布拉泽,而克里斯国信仰象征光明和永恒的神斯普林·布拉 ...