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的更多相关文章

  1. JfreeChart折线图 CSDN-李鹏飞

    今天公司里分配给我的工作是JfreeChart折线图本人之前也没接触过如今让我们大家一起完毕! 在这个公司,用到了太多的JfreeChart,今天就对折线图作一个总结,希望对大家有点帮助,我这里直接是 ...

  2. jfreechart时序图 demo

    import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.io.FileNotFoundExce ...

  3. echarts折线图Demo

    echarts链接:http://echarts.baidu.com/examples/editor.html?c=line-stack 黑底代码:http://gallery.echartsjs.c ...

  4. 微信小程序中-折线图

    echarts配置项太多了,还是一点点积累吧~~~~~ 当然前提条件还是得老老实实看echarts官方文档 :https://echarts.baidu.com/ 今天主要就介绍下我在工作中通过ech ...

  5. matplotlib之折线图

    1.案例一 # coding=utf-8 from matplotlib import pyplot as plt import random # 设置字体相关 from matplotlib imp ...

  6. JFreeChart 图表生成实例(饼图、柱状图、折线图、时序图)

    import java.awt.BasicStroke; import java.awt.Color; import java.io.FileOutputStream; import java.io. ...

  7. java利用JFreeChart实现各种数据统计图(柱形图,饼图,折线图)

    最近在做数据挖掘的课程设计,需要将数据分析的结果很直观的展现给用户,这就要用到数据统计图,要实现这个功能就需要几个第三方包了: 1.       jfreechart-1.0.13.jar 2.    ...

  8. JFreeChart在制作折线图

    JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt.Color; import java.awt.Font; import org ...

  9. struts2整合JFreechart 饼图、折线图、柱形图

    struts2整合JFreechart 饼图.折线图.柱形图 上效果图: 当然可以将数据导出图片格式存储.具体下的链接里的文件有保存成图片的操作. 因为是strust2整合JFreechart,所以s ...

随机推荐

  1. POJ 1044: Date bugs

    题目描述 There are rumors that there are a lot of computers having a problem with the year 2000. As they ...

  2. Kali Linux Wine32英文字体不显示问题

     Kali Linux Wine32英文字体不显示问题 Kali Linux提供了Wine32工具.在运行Wine32后,界面可以显示中文,但不能显示英文文字.英文文字均显示为方块.这是由于缺少对应的 ...

  3. 六. 异常处理8.throws子句

    如果一个方法可以导致一个异常但不处理它,它必须指定这种行为以使方法的调用者可以保护它们自己而不发生异常.做到这点你可以在方法声明中包含一个throws子句.一个 throws 子句列举了一个方法可能抛 ...

  4. Mysql Grant权限

    查看用户权限: SELECT host,user,password,Grant_priv,Super_priv FROM mysql.user; 权限取决于最上一条记录的值 如果需要收回权限: REV ...

  5. centos下mysql集群初尝试

    原文:http://www.lvtao.net/database/mysql-cluster.html 五台服务器篇 安装要求 安装环境:CentOS-6.3安装方式:源码编译安装软件名称:mysql ...

  6. UITableView的HeaderView和FooterView

    header通过下面两个代理方法设置  - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSIntege ...

  7. Unity定制 Image、Text的对象生成

    2016.4.14 昨天看到 雨凇的 Unity3D研究院之UGUI一个优化效率小技巧:  http://www.xuanyusong.com/archives/4006 完好了他所说的代码: usi ...

  8. apache 的rewrite函数配置伪静态

    配置伪静态目的:对于访问比较长的uri,利于网站搜索工具更容易记住,换句话利于SEO 在配置文件中添加或找到 <IfModule mod_rewrite.c> </IfModule& ...

  9. SilverLight-3:SilverLight 备注

    ylbtech_silverlight 一.DebugSilverlight应用程序的方法: 第一种: 1.Silverlight引用命名空间:System.Diagnostics; 2.在程序必要的 ...

  10. JAVA之抽象类与抽象方法

    抽象方法:在类中没有方法体的方法,就是抽象方法.抽象类:含有抽象方法的类就叫抽象类.|||||||||抽象类不能被实例化(new)为什么要使用抽象方法?(以下是个人观点)因 为在面向对象的编程的思想中 ...