File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JBoss/WildFly and the fly likes Problem using JFreeChart Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Products » JBoss/WildFly
Bookmark "Problem using JFreeChart" Watch "Problem using JFreeChart" New topic
Author

Problem using JFreeChart

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
I think this problem is more JBoss than JFreeChart. I've tried putting my jfreechart and jcommon jars into the appropriate WEB-INF/lib directory but it's having problems compiling the jsp that tries and create the chart.
Here is the jsp :
<%@page import="java.util.Enumeration"%>
<%@page import="org.jfree.data.category.*"%>
<%@page import="org.jfree.chart.*"%>
<%@page import="org.jfree.chart.plot.*"%>
<%@page language="java" contentType="image/png" %>

<%!
CategoryDataset getDataset(HttpServletRequest request) {
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
Enumeration paramNames = request.getParameterNames();
while (paramNames.hasMoreElements()) {
String name = (String) paramNames.nextElement();
if (name.startsWith("series")) {
dataset.addValue(Double.parseDouble(request.getParameter(name)), "",
name.substring(6));
}
}
return dataset;
}

JFreeChart createChart(HttpServletRequest request) {
return ChartFactory.createLineChart(
// title - the chart title
request.getParameter("title"),
// domainAxisLabel - the label for the category axis
request.getParameter("domainAxisLabel"),
// rangeAxisLabel - the label for the value axis
request.getParameter("rangeAxisLabel"),
// dataset
getDataset(request),
// orientation
PlotOrientation.VERTICAL,
// show legend
("true".equals(request.getParameter("legend"))),
// tooltips - generate tool tips?
true,
// urls
false);
}
%>

<%
JFreeChart chart = createChart(request);
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache,no-store,max-age=0");
ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 200, 100);
%>

Here is the error messages :
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
CategoryDataset cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
DefaultCategoryDataset cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
DefaultCategoryDataset cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
JFreeChart cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
ChartFactory cannot be resolved

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
PlotOrientation.VERTICAL cannot be resolved to a type

An error occurred at line: 48 in the jsp file: /chart.jsp
Generated servlet error:
JFreeChart cannot be resolved to a type

An error occurred at line: 48 in the jsp file: /chart.jsp
Generated servlet error:
The method createChart(HttpServletRequest) is undefined for the type chart_jsp

An error occurred at line: 48 in the jsp file: /chart.jsp
Generated servlet error:
ChartUtilities cannot be resolved


org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


root cause

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
CategoryDataset cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
DefaultCategoryDataset cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
DefaultCategoryDataset cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
JFreeChart cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
ChartFactory cannot be resolved

An error occurred at line: 13 in the jsp file: /chart.jsp
Generated servlet error:
PlotOrientation.VERTICAL cannot be resolved to a type

An error occurred at line: 48 in the jsp file: /chart.jsp
Generated servlet error:
JFreeChart cannot be resolved to a type

An error occurred at line: 48 in the jsp file: /chart.jsp
Generated servlet error:
The method createChart(HttpServletRequest) is undefined for the type chart_jsp

An error occurred at line: 48 in the jsp file: /chart.jsp
Generated servlet error:
ChartUtilities cannot be resolved


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Any help would be greatly appreciated.

RH
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Try having the jar files in the server/servername(prob default)/lib directory.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
Hi Mark/All,
Heres the directory structure I have.
deploy/MyGraphs.war/
....................WEB-INF/
............................lib/
................................jcommon-1.0.9.jar
................................jfreechart-1.0.5.jar
............................chart-html.jsp
............................chart.jsp

The guy that gave me this example has the chart-html.jsp as just html and an img tag in there that points to the jsp that creates the image. He said it works fine for him but I can't seem to get it working. Any help greatly appreciated.

RH
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Have you tried my suggestion. Putting those two jars, not in your war file, but in the server\default\lib directory?

Mark
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9335
    
110

This does not appear to be a classloader issue. It's a genuine compilation error. Looks like you are using a older version of JFreechart (in which the CategoryDataset class is under org.jfree.data package and not org.jfree.data.category.) The latest version of JFreechart has its classes refactored. You will have to use JFreeChart 1.0.5 library to get this jsp running.


[My Blog] [JavaRanch Journal]
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
I tried the jars under WEB-INF/lib and extracted them in classes to give it a try. I tried it underneath JBoss/lib, under the default/lib, and under deploy directly and still didn't work.
I'm running the latest jfreechart but I guess the source I got it from may be using an older version. I'll have to check. Will re-post if I find anything. Thanks for the feedback guys.

RH
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
As I stated in the last posting though, I am using 1.0.5 (it's where I mention where I put the jars). I double checked (after extracting the jar) and the class is where it's being referenced. Any ideas with this in mind? Thanks again for the help.

RH
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9335
    
110

Create a file named jboss-web.xml having the following contents and place it in the WEB-INF folder of your war file. Then after restarting the server try your jsp.



This will help us figure out if your jsp is picking up a different version of the JFreeChart library from the classpath.
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
Hi Guys,
I thought I would re-post after looking at it again. I had the latest version of JFreeChart but the examples were expecting an older version whereby the hierarchy was restructured. Thanks for the help.

Rob
Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 805
I had it working but now I get this (from when it was working to now I had made zero changes). We have however added another .war file to the default server and the lib and classes directories underneath the .war directory in question may have gotten overwritten. Help would be very much appreciated.

java.lang.NullPointerException: Null 'text' argument.
org.jfree.chart.title.TextTitle.<init>(TextTitle.java:215)
org.jfree.chart.title.TextTitle.<init>(TextTitle.java:176)
org.apache.jsp.chart_jsp.createChart(chart_jsp.java:55)
org.apache.jsp.chart_jsp._jspService(chart_jsp.java:154)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Rob
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Rob, could you please post this in a new thread. I got confused when I saw that there was a reply to this thread, and it is a different error, and not really related to what you had before.

Thanks

Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using JFreeChart
 
Similar Threads
Charts In JSP
problem using jfreechart
Can't deploy code for taglibs on Tomcat 5.5
JR Free Web Chart Component
Charts In JSP