This is the code (found on forums here):
<%@ page contentType="text/html; charset=windows-1250" %>
<%@page import = "org.jfree.chart.*"%>
<%@page import = "org.jfree.data.*"%>
<html>
<head>
<title>
chart
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Hello world
</h1>
<html>
<%
DefaultPieDataset pieDataset = new DefaultPieDataset();
pieDataset.setValue("java",new Integer(75));
pieDataset.setValue("other",new Integer(25));
JFreeChart chart = ChartFactory.createPieChart("sample piechart", pieDataset, true);
%>
</body>
</html>
Jars are uploaded to WEB-INF\lib and classes to WEB-INF classes. Still there is an error DefaulPieDataSet not found!?
I would apreciate some help please.
Problem using JFree under Resin
Try out these buddy

Code: Select all
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.chart.ChartUtilities;
Code: Select all
CategoryDataset dataset = createDataset();
JFreeChart chart = ChartFactory.createBarChart3D("My 3D Bar Chart", "My X axis", "My Y Axis", dataset, PlotOrientation.VERTICAL, true, false, false);
response.setContentType("image/jpeg");
ServletOutputStream objSos = response.getOutputStream();
ChartUtilities.writeChartAsJPEG(objSos, chart, 600, 400);
Thanx, it seems to work, but now it says that the image "xy.jsp" cannot be displayed because it contain errors. Here is the code:
<%@ page contentType="text/html; charset=windows-1250" %>
<%@ page import ="org.jfree.chart.ChartFactory"%>
<%@ page import ="org.jfree.chart.JFreeChart"%>
<%@ page import ="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import ="org.jfree.data.category.CategoryDataset"%>
<%@ page import ="org.jfree.data.category.DefaultCategoryDataset"%>
<%@ page import ="org.jfree.chart.ChartUtilities"%>
<html>
<head>
<title>
chart
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Hello world
</h1>
<%
String graphURL;
String filename;
try{
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(new Double(100.0),"","Machico");
dataset.setValue(new Double(80.0),"", "Caniço");
dataset.setValue(new Double(60.0),"", "Gaula");
dataset.setValue(new Double(40.0), "","Santana");
JFreeChart chart = ChartFactory.createBarChart3D("My 3D Bar Chart", "My X axis", "My Y Axis", dataset, PlotOrientation.VERTICAL, true, false, false);
response.setContentType("image/png");
ServletOutputStream objSos = response.getOutputStream();
ChartUtilities.writeChartAsPNG(objSos, chart, 600, 400);
}
catch(Exception a){
out.println("<p>Erro no JSP"+a.getMessage()+"</p>");
}
%>
</body>
</html>
I am sorry that I don't understand that, but the documentation is not very helpful.
<%@ page contentType="text/html; charset=windows-1250" %>
<%@ page import ="org.jfree.chart.ChartFactory"%>
<%@ page import ="org.jfree.chart.JFreeChart"%>
<%@ page import ="org.jfree.chart.plot.PlotOrientation"%>
<%@ page import ="org.jfree.data.category.CategoryDataset"%>
<%@ page import ="org.jfree.data.category.DefaultCategoryDataset"%>
<%@ page import ="org.jfree.chart.ChartUtilities"%>
<html>
<head>
<title>
chart
</title>
</head>
<body bgcolor="#ffffff">
<h1>
Hello world
</h1>
<%
String graphURL;
String filename;
try{
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.setValue(new Double(100.0),"","Machico");
dataset.setValue(new Double(80.0),"", "Caniço");
dataset.setValue(new Double(60.0),"", "Gaula");
dataset.setValue(new Double(40.0), "","Santana");
JFreeChart chart = ChartFactory.createBarChart3D("My 3D Bar Chart", "My X axis", "My Y Axis", dataset, PlotOrientation.VERTICAL, true, false, false);
response.setContentType("image/png");
ServletOutputStream objSos = response.getOutputStream();
ChartUtilities.writeChartAsPNG(objSos, chart, 600, 400);
}
catch(Exception a){
out.println("<p>Erro no JSP"+a.getMessage()+"</p>");
}
%>
</body>
</html>
I am sorry that I don't understand that, but the documentation is not very helpful.