package com.htcf.dashbord; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Point; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.dial.DialBackground; import org.jfree.chart.plot.dial.DialCap; import org.jfree.chart.plot.dial.DialPlot; import org.jfree.chart.plot.dial.DialTextAnnotation; import org.jfree.chart.plot.dial.DialValueIndicator; import org.jfree.chart.plot.dial.StandardDialFrame; import org.jfree.chart.plot.dial.StandardDialRange; import org.jfree.chart.plot.dial.StandardDialScale; import org.jfree.data.general.DefaultValueDataset; import org.jfree.ui.GradientPaintTransformType; import org.jfree.ui.StandardGradientPaintTransformer; /** * @description 构造数据,测试仪表盘图片生成 */ public class DashBords { public static void main(String[] args) { DashBords test = new DashBords(); test.getDataSet(); test.temperatureData(); } public void getDataSet(){ //数据集合对象 DefaultValueDataset dataset = new DefaultValueDataset(); //当前指针指向的位置,即:我们需要显示的数据 dataset = new DefaultValueDataset(20D); //实例化DialPlot DialPlot dialplot = new DialPlot(); //设置数据集合 dialplot.setDataset(dataset); //开始设置显示框架结构 StandardDialFrame standarddialframe= new StandardDialFrame(); standarddialframe.setBackgroundPaint(Color.black);//Color.lightGray standarddialframe.setForegroundPaint(Color.darkGray);//圆边的颜色 dialplot.setDialFrame(standarddialframe); //结束设置显示框架结构 GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground dialbackground = new DialBackground(gradientpaint); dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); dialplot.setBackground(dialbackground); //设置显示在表盘中央位置的信息 DialTextAnnotation dialtextannotation = new DialTextAnnotation("成本执行"); dialtextannotation.setFont(new Font("Dialog", 17, 17)); dialtextannotation.setRadius(0.6D);//字体距离圆心的距离 dialplot.addLayer(dialtextannotation); DialValueIndicator dialvalueindicator = new DialValueIndicator(0); dialplot.addLayer(dialvalueindicator); //根据表盘的直径大小(0.88),设置总刻度范围 StandardDialScale standarddialscale = new StandardDialScale(0.0D,100.0D,-120.0D,-300.0D,10D,9); standarddialscale.setTickRadius(0.9D); standarddialscale.setTickLabelOffset(0.1D);//显示数字 距离圆边的距离 standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14)); //主意是 dialplot.addScale()不是dialplot.addLayer() dialplot.addScale(0, standarddialscale); //设置刻度范围(红色) StandardDialRange standarddialrange = new StandardDialRange(0D, 50D, Color.green); standarddialrange.setInnerRadius(0.6D); standarddialrange.setOuterRadius(0.62D); dialplot.addLayer(standarddialrange); //设置刻度范围(橘黄色) StandardDialRange standarddialrange1 = new StandardDialRange(50D, 80D, Color.orange); standarddialrange1.setInnerRadius(0.6D);// 半径返回两条线 standarddialrange1.setOuterRadius(0.62D); dialplot.addLayer(standarddialrange1); //设置刻度范围(绿色) StandardDialRange standarddialrange2 = new StandardDialRange(80D, 100D, Color.red); standarddialrange2.setInnerRadius(0.6D); standarddialrange2.setOuterRadius(0.62D); dialplot.addLayer(standarddialrange2); //设置指针 org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(); dialplot.addLayer(pointer); //实例化DialCap DialCap dialcap = new DialCap(); dialcap.setRadius(0.1D);//指针中心圆的大小 dialplot.setCap(dialcap); //生成chart对象 JFreeChart jfreechart = new JFreeChart(dialplot); //设置标题 jfreechart.setTitle("目标成本执行情况分析"); DashBords testBords = new DashBords(); testBords.saveAsFile(jfreechart, "d:\\jfreechart\\dashbord_"+Math.random()*20+".png", 400, 400); } public void temperatureData(){ //数据集合对象 DefaultValueDataset dataset = new DefaultValueDataset(); //当前指针指向的位置,即:我们需要显示的数据 dataset = new DefaultValueDataset(16D); //实例化DialPlot DialPlot dialplot = new DialPlot(); //设置数据集合 dialplot.setDataset(dataset); //开始设置显示框架结构 StandardDialFrame standarddialframe= new StandardDialFrame(); standarddialframe.setBackgroundPaint(Color.lightGray); standarddialframe.setForegroundPaint(Color.darkGray);//圆边的颜色 dialplot.setDialFrame(standarddialframe); //结束设置显示框架结构 GradientPaint gradientpaint = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(), new Color(170, 170, 220)); DialBackground dialbackground = new DialBackground(gradientpaint); dialbackground.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL)); dialplot.setBackground(dialbackground); //设置显示在表盘中央位置的信息 DialTextAnnotation dialtextannotation = new DialTextAnnotation("温度"); dialtextannotation.setFont(new Font("Dialog", 1, 14)); dialtextannotation.setRadius(0.69999999999999996D);//字体距离圆心的距离 dialplot.addLayer(dialtextannotation); DialValueIndicator dialvalueindicator = new DialValueIndicator(0); dialplot.addLayer(dialvalueindicator); //根据表盘的直径大小(0.88),设置总刻度范围 StandardDialScale standarddialscale = new StandardDialScale(-40D,60D,-120.0D,-300.0D,10D,9);//??? standarddialscale.setTickRadius(0.88D); standarddialscale.setTickLabelOffset(0.14999999999999999D);//显示数字 距离圆边的距离 standarddialscale.setTickLabelFont(new Font("Dialog", 0, 14)); //主意是 dialplot.addScale()不是dialplot.addLayer() dialplot.addScale(0, standarddialscale); //设置刻度范围(红色) StandardDialRange standarddialrange = new StandardDialRange(40D, 60D, Color.red); standarddialrange.setInnerRadius(0.52000000000000002D); standarddialrange.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange); //设置刻度范围(橘黄色) StandardDialRange standarddialrange1 = new StandardDialRange(10D, 40D, Color.orange); standarddialrange1.setInnerRadius(0.52000000000000002D);// 半径返回两条线 standarddialrange1.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange1); //设置刻度范围(绿色) StandardDialRange standarddialrange2 = new StandardDialRange(-40D, 10D, Color.green); standarddialrange2.setInnerRadius(0.52000000000000002D); standarddialrange2.setOuterRadius(0.55000000000000004D); dialplot.addLayer(standarddialrange2); //设置指针 org.jfree.chart.plot.dial.DialPointer.Pointer pointer = new org.jfree.chart.plot.dial.DialPointer.Pointer(); dialplot.addLayer(pointer); //实例化DialCap DialCap dialcap = new DialCap(); dialcap.setRadius(0.1D);//指针中心圆的大小 dialplot.setCap(dialcap); //生成chart对象 JFreeChart jfreechart = new JFreeChart(dialplot); //设置标题 jfreechart.setTitle("设备取水温度采样"); DashBords testBords = new DashBords(); testBords.saveAsFile(jfreechart, "d:\\jfreechart\\dashbord_"+Math.random()*20+".png", 400, 400); } /**保存为文件*/ public void saveAsFile(JFreeChart chart, String outputPath, int width, int height) { FileOutputStream out = null; try { File outFile = new File(outputPath); if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs(); } out = new FileOutputStream(outputPath); // 保存为PNG ChartUtilities.writeChartAsPNG(out, chart, width, height); // 保存为JPEG // ChartUtilities.writeChartAsJPEG(out, chart, width, height); out.flush(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (out != null) { try { out.close(); } catch (IOException e) { } } } } }
相关推荐
JfreeChartDemo 仪表盘
利用jfreechart制作动态仪表盘
根据 JFreeChart 生成仪表盘, public static void main(String[] args) { System.out.println(new HC().getHC("TEST","123")); }
JfreeChart 仪表盘
JFreeChart 是Java用来做仪表盘不错的类包.该下载中可以有 源码(本人注释非常清晰),类包,效果图!该源码特别适合 WEB 项目中对 仪表盘的需求 !
博文链接:https://zhaoyl.iteye.com/blog/235330
一个用Jfreechart实现的硬盘数据转换器,读入硬盘数据,转换为三种图像。
java利用JFreeChart实现各类数据统计图柱形图饼图折线图.pdf
java利用JFreeChart实现各种数据统计图(柱形图_饼图_折线图).pdf
struts2整合 jfreechart 实现报表组件
Struts2整合JFreeChart 实现柱状图表、Struts2整合JFreeChart 实现柱状图表、Struts2整合JFreeChart 实现柱状图表。
java中关于JFreeChart实现实时曲线图
Java使用SWT JFreeChart控件实现的小游戏.zipJava使用SWT JFreeChart控件实现的小游戏.zipJava使用SWT JFreeChart控件实现的小游戏.zipJava使用SWT JFreeChart控件实现的小游戏.zipJava使用SWT JFreeChart控件实现的...
用jfreechart实现动态曲线,有系统产生随机数,然后画出曲线,并能实时显示曲线
Jfreechart实现多项式趋势线,没有装excel,所以还没有测试是否和excel一至,也就是多项式拟合未验证是否和excel一至
今天在网上查了一下,没有发现 Jfreechart柱状图排序的实现方法,也还没来得及研究Jfreechart的代码和文档,所以就自己实现了一下。可能jfreechart自身有这个功能,可是发现以前的这个功能无效了,不知道用什么新...
用JfreeChart实现在jsp页面画甘特图,里面包括项目源码和数据库信息表,以及参照资料和一些资料的网址
为了做项目开发而对jfreechart的仪表使用进行了细致分析
一份非常简单的jfreechart折线图demo!!!!!!!!