码迷,mamicode.com
首页 > 其他好文 > 详细

[二]JFreeChart实践一

时间:2015-12-27 21:45:09      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

生成一张简单的图片

java代码:

package com.lxl.chart;

import javax.servlet.http.HttpSession;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.category.DefaultCategoryDataset;

public class ChartDemo {

public static String getChartName(HttpSession session) throws Exception {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(200, "包头", "茄子");
dataset.addValue(300, "包头", "辣椒");
dataset.addValue(400, "包头", "皇冠");
dataset.addValue(500, "包头", "苹果");
JFreeChart chart = ChartFactory.createBarChart3D("蔬菜价格表", "", "", dataset, PlotOrientation.VERTICAL, true, true,
true);
String chartName = ServletUtilities.saveChartAsPNG(chart, 700, 500,null, session);
return chartName;
}
}

web.xml

<servlet>
<servlet-name>DisplayChart</servlet-name>
<servlet-class>org.jfree.chart.servlet.DisplayChart</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DisplayChart</servlet-name>
<url-pattern>/DisplayChart</url-pattern>
</servlet-mapping>

 

jsp页面:

<%@page import="com.lxl.chart.ChartDemo"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<%
String name = ChartDemo.getChartName(session);
System.out.println(name);
%>
<body>
<img src="DisplayChart?filename=<%=name%>" width="700" height="500" border="0">
</body>
</html>

 

[二]JFreeChart实践一

标签:

原文地址:http://www.cnblogs.com/luoxiaolei/p/5080766.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!