jfreechart折线图 demo
public class ChartUtil {
public static ChartUtil chartUtil;
private RoomViewsDataService roomViewsDataService;
/**
* 创建报表图
* @return
* @throws IOException
*/
public static String createChartImage(String userId ,String userName , String livingId) throws IOException{
//生成3D折线图(柱状图只改方法名createLineChart3D就可以了)
JFreeChart chart = ChartFactory.createLineChart (
userName + "直播统计图", //图表标题
"时间(分钟)", //目录轴的显示标签
"人数", //数值轴的显示标签
getDataSet(livingId), //数据
//PlotOrientation.HORIZONTAL, //图表方向水平
PlotOrientation.VERTICAL, //图表方向垂直
true, //是否显示图例
true, //是否显示工具提示
true //是否生成URL
);
//设置标题及标题字体
chart.setTitle(new TextTitle(userName + "直播统计图",new Font("黑体",Font.ITALIC,22)));
//建一个图例
LegendTitle legendTitle = chart.getLegend(0);
//设置图例字体
legendTitle.setItemFont(new Font("宋体",Font.BOLD,14));
//获取折线图plot对象
CategoryPlot plot = (CategoryPlot) chart.getPlot();
//设置折线的颜色
plot.getRenderer().setSeriesPaint(0, Color.RED);
// plot.getRenderer().setSeriesPaint(1, Color.GREEN);
// plot.getRenderer().setSeriesPaint(2, Color.ORANGE);
//取得横轴
CategoryAxis categoryAxis = plot.getDomainAxis();
//设置横轴的字体
categoryAxis.setLabelFont(new Font("宋体",Font.BOLD,12));
//设置分类标签以45度倾斜
//categoryAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45);
//设置分类标签字体
categoryAxis.setTickLabelFont(new Font("宋体",Font.BOLD,12));
//取得纵轴
NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis();
//Y轴显示整数
numberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
//设置纵轴的字体
numberAxis.setLabelFont(new Font("宋体",Font.BOLD,12));
//设置背景透明度(0~1)
plot.setBackgroundAlpha(0.9f);
//设置前景色透明度(0~1)
plot.setForegroundAlpha(0.5f);
//输出文件
String filePath = CreateDelFileUtils.delAndCreateSessionUser(userId ,userName) + "/" + userId + ".jpg";
System.out.println(filePath);
FileOutputStream fos = new FileOutputStream(filePath);
//用ChartUtilities工具输出
ChartUtilities.writeChartAsJPEG(fos, chart, 650, 350);
fos.close();
return filePath;
}
/**
* 设置数据集
* @return
*/
private static CategoryDataset getDataSet(String livingId) {
//提供生成折线图的数据
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//生成复杂带图例的柱状图
List<RoomViewsDataModel> rvdms = chartUtil.roomViewsDataService.getDataByLivinId(livingId);
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
for(int i = 0 , n = rvdms.size() ; i < n; i++){
dataset.addValue(rvdms.get(i).getViews(), "人数", sdf.format(rvdms.get(i).getDate()));
}
return dataset;
}
public RoomViewsDataService getRoomViewsDataService() {
return roomViewsDataService;
}
public void setRoomViewsDataService(RoomViewsDataService roomViewsDataService) {
this.roomViewsDataService = roomViewsDataService;
}
public void init(){
chartUtil = this;
chartUtil.roomViewsDataService = roomViewsDataService;
}
}
jfreechart折线图 demo的更多相关文章
- JfreeChart折线图 CSDN-李鹏飞
今天公司里分配给我的工作是JfreeChart折线图本人之前也没接触过如今让我们大家一起完毕! 在这个公司,用到了太多的JfreeChart,今天就对折线图作一个总结,希望对大家有点帮助,我这里直接是 ...
- jfreechart时序图 demo
import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.io.FileNotFoundExce ...
- echarts折线图Demo
echarts链接:http://echarts.baidu.com/examples/editor.html?c=line-stack 黑底代码:http://gallery.echartsjs.c ...
- 微信小程序中-折线图
echarts配置项太多了,还是一点点积累吧~~~~~ 当然前提条件还是得老老实实看echarts官方文档 :https://echarts.baidu.com/ 今天主要就介绍下我在工作中通过ech ...
- matplotlib之折线图
1.案例一 # coding=utf-8 from matplotlib import pyplot as plt import random # 设置字体相关 from matplotlib imp ...
- JFreeChart 图表生成实例(饼图、柱状图、折线图、时序图)
import java.awt.BasicStroke; import java.awt.Color; import java.io.FileOutputStream; import java.io. ...
- java利用JFreeChart实现各种数据统计图(柱形图,饼图,折线图)
最近在做数据挖掘的课程设计,需要将数据分析的结果很直观的展现给用户,这就要用到数据统计图,要实现这个功能就需要几个第三方包了: 1. jfreechart-1.0.13.jar 2. ...
- JFreeChart在制作折线图
JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt.Color; import java.awt.Font; import org ...
- struts2整合JFreechart 饼图、折线图、柱形图
struts2整合JFreechart 饼图.折线图.柱形图 上效果图: 当然可以将数据导出图片格式存储.具体下的链接里的文件有保存成图片的操作. 因为是strust2整合JFreechart,所以s ...
随机推荐
- hdu3507(初识斜率优化DP)
hdu3507 题意 给出 N 个数字,输出的时候可以选择连续的输出,每连续输出一串,它的费用是 这串数字和的平方加上一个常数 M. 分析 斜率优化dp,入门题. 参考 参考 得到 dp 方程后,发现 ...
- 你也许还不知道const_cast,static_cast,dynamic_cast,reinterpret_cast的区别吧?
[QQ群: 189191838,对算法和C++感兴趣可以进来] 开篇立意: C++中各种转换令人眼花缭乱,看似差不多,实际差很多,而且在当今时间,做一个"差不多先生"其 ...
- Ubuntu 16.04桌面版GUI网络配置工具NetworkManager的命令行工具nm-tool无法使用的问题
说明: 1.Ubuntu中分桌面版和服务器版,而这两个版本在网络管理方面使用的工具都不一样,尤其是在桌面版,使用了NetworkManager进行管理. 2.服务器版使用的是命令行配置,而桌面版包含了 ...
- Tiny4412在Ubuntu下给MiniTools添加快捷方式
解压MiniTools-Linux-20140317.tgz root@ubuntu:~/tiny4412/MiniTools-# ls -l total -rw-r--r-- root root M ...
- 【mybatis】时间范围 处理时间格式问题 + 查询当天 本月 本年 + 按当天 当月 范围 查询 分组
1.mybatis中查询时间范围处理: 例如2018-05-22 ~2018-05-23 则查出来的数据仅能查到2018-05-22的,查不到2018-05-23的数据! 为什么会这样? 明明时间字段 ...
- homebrew代理设置
方法一 brew用curl下载,所以给curl挂上socks5的代理即可. 在~/.curlrc文件中输入代理地址即可. socks5 = "127.0.0.1:1080" 方法二 ...
- Console-算法:fun1(do while)
ylbtech-Arithmetic:Console-算法[do while]-XX 1.A,Demo(案例) 1.B,Solution(解决方案) using System; namespace ...
- Python转码问题的解决方法
FROM: http://www.jb51.net/article/16104.htm 在Python中,可以对String调用decode和encode方法来实现转码. 比如,若要将某个St ...
- cmd.exe启动参数说明
启动命令解释程序 Cmd.exe 的新范例.如果在不含参数的情况下使用,cmd 将显示操作系统的版本和版权信息. 语法 cmd [{/c | /k}] [/s] [/q] [/d] [{/a | /u ...
- eCos系统无法正确链接到在C++源文件里自己定义的cyg_user_start函数的问题和解决的方法
在C++源文件里定义cyg_user_start函数前,将其声明成C函数.就可以解决这个问题. eCos官网:http://ecos.sourceware.org eCos中文技术网:http://w ...