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 ...
随机推荐
- MyEclipse 10.0安装图解
- Ubuntu下触控板手势调节软件xSwipe
楼主进了一台Thinkpad T450s,触控板支持4点触控,安装了ubuntu14.04 LTS之后,触控板只剩下双指滑动了,略有不爽,各种google,百度. 真找到办法了. 首先得知了touch ...
- luogu P1182 数列分段Section II
题目描述 对于给定的一个长度为N的正整数数列A[i],现要将其分成M(M≤N)段,并要求每段连续,且每段和的最大值最小. 关于最大值最小: 例如一数列4 2 4 5 1要分成3段 将其如下分段: [4 ...
- 关于MapControl和PageLayout地图同步的问题
按照ArcMap的处理方式,地图和制图是分两个页面的,他们之间通过共享同一个Map对象来实现地图同步,具体做法就是在PageLayoutControl的PageLayoutReplaced事件发生时, ...
- iOS8下的远程推送
本篇文章主要介绍了"iOS8下的远程推送",主要涉及到方面的内容,对于IOS开发感兴趣的同学可以参考一下: 昨天做了一下远程推送,今天写下来,分享给需要的人.参考了很多篇文章,或许 ...
- Bluetooth篇 开发实例之八 匹配
自己写的App匹配蓝牙设备,不需要通过系统设置去连接. 匹配和通信是两回事. 用过Android系统设置(Setting)的人都知道蓝牙搜索之后可以建立配对和解除配对,但是这两项功能的函数没有在SDK ...
- Java:集合类的区别详解
Java中集合类的区别 Array是数组,不在集合框架范畴之内,一旦选定了,它的容量大小就不能改变了,所以通常在编程中不选用数组来存放. 集合 : 集合对象:用于管理其他若干对象的对象 数组:长度不可 ...
- c++之map函数/迭代器
参考文献:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html #include <iostream> #include < ...
- 16个Linux服务器监控命令
在不同的Linux发行版中,会有不同的GUI程序可以显示各种系统信息,比如SUSE linux发行版中,就有非常棒的图形化的配置和管理工具YaST,KDE桌面环境里的KDE System Guard也 ...
- selenium firefox设置代理
from selenium import webdriver profile = webdriver.FirefoxProfile() profile.set_preference('network. ...