Problem using JFree under Resin

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Zvonko

Problem using JFree under Resin

Post by Zvonko » Fri Nov 25, 2005 9:36 am

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.

Guest

Post by Guest » Fri Nov 25, 2005 10:43 am

OK. I changed second import to
<%page import = "org.jfree.data.general.*"%>
and removed <html> tag after </h1>.
Now, there is no errors, but there is no Pie chart either, only heading Helllo World.

Any ideas what am I doing wrong?

Souma
Posts: 17
Joined: Sun Nov 20, 2005 4:02 am

Post by Souma » Fri Nov 25, 2005 11:04 am

Try out these buddy :wink:

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);

zvonko

Post by zvonko » Fri Nov 25, 2005 11:27 am

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.

Locked