i hope it can bring a lot of help for you
/**
*this class file for create your chart
*/
package helloservlet;
import java.io.*;
import org.jfree.chart.*;
import org.jfree.data.*;
public class myDemoChart {
public myDemoChart() {
}
private DefaultPieDataset getDataSet() {
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("C++", 700);
dataset.setValue("JAVA", 300);
dataset.setValue("Delphi", 200);
dataset.setValue("ada", 400);
dataset.setValue("smalltalk", 50);
dataset.setValue("perl", 100);
dataset.setValue("php", 120);
return dataset;
}
public void getchart(OutputStream resp) {
DefaultPieDataset data = getDataSet();
JFreeChart chart = ChartFactory.createPie3DChart("program language",
data, true, false, false);
try {
ChartUtilities.writeChartAsJPEG(resp, 100, chart, 700, 500, null);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* this class file is a servlet
*/
package helloservlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Servlet1 extends HttpServlet {
private static final String CONTENT_TYPE = "image/jpeg";
public void init() throws ServletException {
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
myDemoChart tmp = new myDemoChart();
tmp.getchart(response.getOutputStream()) ;
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
//Process the HTTP Put request
public void doPut(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
//Clean up resources
public void destroy() {
}
}
/**
* this is a jsp file
*/
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
jsp1
</title>
</head>
<jsp:useBean id="myDemoChart" scope="session" class="helloservlet.myDemoChart" />
<jsp:setProperty name="jsp1BeanId" property="*" />
<body bgcolor="#ffffff">
<h1>
hello jfreeChart
</h1>
<%
response.setContentType("image/jpeg");
myDemoChart.getchart(response.getOutputStream());
%>
<form method="post">
<br>Enter new value : <input name="sample"><br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
</form>
</body>
</html>