/**
**QQ:252574345
**MSN:[email protected]
*/
最近因为业务需要,希望对一个设备的温度进行监控,为了直观描述其温度变化,所以利用 JFreeChart做了下面的图形
本工程例环境:
Jfreechart1.0.6
eclipse 3.2
tomcat 5.0.28
效果如图:
代码如下:(付后下载)
tep.jsp
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.awt.Color,
org.jfree.chart.ChartFactory,
org.jfree.chart.JFreeChart,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.CategoryDataset,
org.jfree.data.general.*,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.axis.CategoryAxis,
org.jfree.chart.axis.ValueAxis,
org.jfree.chart.renderer.category.BarRenderer3D,
org.jfree.chart.urls.StandardCategoryURLGenerator,
org.jfree.chart.*,
org.jfree.chart.entity.*,
org.jfree.chart.labels.*,
org.jfree.chart.axis.CategoryLabelPositions,
java.awt.Font,
java.awt.GradientPaint,
org.jfree.ui.TextAnchor,
org.jfree.chart.axis.NumberAxis,
org.jfree.chart.axis.NumberTickUnit,
java.text.DecimalFormat,
org.jfree.chart.plot.ThermometerPlot,
org.jfree.data.general.DefaultValueDataset
"%>
<%
DefaultValueDataset defaultvaluedataset = new DefaultValueDataset(37.2);
ThermometerPlot thermometerplot = new ThermometerPlot(defaultvaluedataset);
JFreeChart chart = new JFreeChart("设备取水温度采样", thermometerplot);
chart.setBackgroundPaint(Color.white);
String filename = ServletUtilities.saveChartAsPNG(chart, 400, 300, session);
//调用DisplayChart(配置在webxml中),生成图形
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
%>
<table width="100%">
<tr>
<td align="center">
<!-- 生成图形 -->
<img src="<%= graphURL %>" width=400 height=300 border=0 alt="">
</td>
</tr>
</table>