jfreechart 折线图

准备工作在上一篇文章,
jsp代码:

<%
TimeSeriesCollection dataTimeSet = new TimeSeriesCollection();
TimeSeries timesre = new TimeSeries("折线图", Day.class);



timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-01-02")), 1000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-02-02")), 2000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-03-02")), 3000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-04-02")), 2000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-05-02")), 4000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-06-02")), 5000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-07-02")), 6000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-08-02")), 9000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-09-02")), 1000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2009-10-02")), 2000);
timesre.add(new Day(new SimpleDateFormat("yyyy-MM-dd").parse("2010-01-02")), 6000);
dataTimeSet.addSeries(timesre);
JFreeChart chartTime = ChartFactory.createTimeSeriesChart("折线图",
"生产日期", "工作点数", dataTimeSet, true, true, false);
chartTime.setBackgroundPaint(Color.white);
XYPlot plot = (XYPlot) chartTime.getXYPlot();
plot.setBackgroundPaint(Color.white);//设置网格背景色
plot.setDomainGridlinePaint(Color.LIGHT_GRAY);//设置网格竖线(Domain轴)颜色
plot.setRangeGridlinePaint(Color.LIGHT_GRAY);//设置网格横线颜色
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));//设置曲线图与xy轴的距离
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYItemRenderer r = plot.getRenderer();
if (r instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
}
//设置Y轴
NumberAxis numAxis = (NumberAxis) plot.getRangeAxis();
NumberFormat numFormater = NumberFormat.getNumberInstance();
//设置显示值的小数点个数
numFormater.setMinimumFractionDigits(2);
numAxis.setNumberFormatOverride(numFormater);
//设置Y周范围
//numAxis.setLowerBound(200);
//numAxis.setUpperBound(7000);

//设置X轴(日期轴)
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MM-dd"));
ChartRenderingInfo info = new ChartRenderingInfo(
new StandardEntityCollection());
String fileName = ServletUtilities.saveChartAsPNG(chartTime, 600,
350, info, session);//生成图片

//String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath()
+ "/servlet/DisplayChart?filename=" + fileName;
%>


同样页面中引用图片地址

<table>
<tr align="center">
<img src="<%=graphURL%>" width=500 height=300 border=0
usemap="#map0">
</tr>
</table>


折线图结果:

[img]http://dl.iteye.com/upload/attachment/260052/4044e46d-a4d6-3711-a267-39b859dc0735.png[/img]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值