GeeCON Prague 2014*
The moose likes Other Open Source Projects and the fly likes Charts In JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Charts In JSP" Watch "Charts In JSP" New topic
Author

Charts In JSP

Gaurav x Jain
Ranch Hand

Joined: Feb 01, 2011
Posts: 39
Hi Friends I am trying to compile following code for genrate a Chart in JSP.

Code
=====

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<%@ page import="java.awt.*" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jfree.chart.*" %>
<%@ page import="org.jfree.chart.axis.*" %>
<%@ page import="org.jfree.chart.entity.*" %>
<%@ page import="org.jfree.chart.labels.*" %>
<%@ page import="org.jfree.chart.plot.*" %>
<%@ page import="org.jfree.chart.renderer.category.*" %>
<%@ page import="org.jfree.chart.urls.*" %>
<%@ page import="org.jfree.data.category.*" %>
<%@ page import="org.jfree.data.general.*" %>

<%
final double[][] data = new double[][]{
{210, 300, 320, 265, 299},
{200, 304, 201, 201, 340}
};

final CategoryDataset dataset =
DatasetUtilities.createCategoryDataset(
"Team ", "", data);

final JFreeChart chart = ChartFactory.createAreaChart(
"Area Chart", "", "Value", dataset,
PlotOrientation.VERTICAL,
true, true, false);

final CategoryPlot plot = chart.getCategoryPlot();
plot.setForegroundAlpha(0.5f);

chart.setBackgroundPaint(new Color(249, 231, 236));

try {
final ChartRenderingInfo info = new ChartRenderingInfo
(new StandardEntityCollection());

final File file1 = new File("..//Workspaces//TestJSP//WebContent//WEB-INF//areachart.png");

ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
} catch (Exception e) {
out.println(e);
}

%>

<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<IMG BORDER="0" <br /> >
</body>
</html>
----------------------------------

Facing below error:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

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

An error occurred at line: 23 in the jsp file: /TestChart.jsp
CategoryDataset cannot be resolved to a type
20: {200, 304, 201, 201, 340}
21: };
22:
23: final CategoryDataset dataset =
24: DatasetUtilities.createCategoryDataset(
25: "Team ", "", data);
26:


An error occurred at line: 24 in the jsp file: /TestChart.jsp
DatasetUtilities cannot be resolved
21: };
22:
23: final CategoryDataset dataset =
24: DatasetUtilities.createCategoryDataset(
25: "Team ", "", data);
26:
27: final JFreeChart chart = ChartFactory.createAreaChart(


An error occurred at line: 27 in the jsp file: /TestChart.jsp
JFreeChart cannot be resolved to a type
24: DatasetUtilities.createCategoryDataset(
25: "Team ", "", data);
26:
27: final JFreeChart chart = ChartFactory.createAreaChart(
28: "Area Chart", "", "Value", dataset,
29: PlotOrientation.VERTICAL,
30: true, true, false);


An error occurred at line: 27 in the jsp file: /TestChart.jsp
ChartFactory cannot be resolved
24: DatasetUtilities.createCategoryDataset(
25: "Team ", "", data);
26:
27: final JFreeChart chart = ChartFactory.createAreaChart(
28: "Area Chart", "", "Value", dataset,
29: PlotOrientation.VERTICAL,
30: true, true, false);


An error occurred at line: 29 in the jsp file: /TestChart.jsp
PlotOrientation.VERTICAL cannot be resolved to a type
26:
27: final JFreeChart chart = ChartFactory.createAreaChart(
28: "Area Chart", "", "Value", dataset,
29: PlotOrientation.VERTICAL,
30: true, true, false);
31:
32: final CategoryPlot plot = chart.getCategoryPlot();


An error occurred at line: 32 in the jsp file: /TestChart.jsp
CategoryPlot cannot be resolved to a type
29: PlotOrientation.VERTICAL,
30: true, true, false);
31:
32: final CategoryPlot plot = chart.getCategoryPlot();
33: plot.setForegroundAlpha(0.5f);
34:
35: chart.setBackgroundPaint(new Color(249, 231, 236));


An error occurred at line: 38 in the jsp file: /TestChart.jsp
ChartRenderingInfo cannot be resolved to a type
35: chart.setBackgroundPaint(new Color(249, 231, 236));
36:
37: try {
38: final ChartRenderingInfo info = new ChartRenderingInfo
39: (new StandardEntityCollection());
40:
41: final File file1 = new File("..//Workspaces//TestJSP//WebContent//WEB-INF//areachart.png");


An error occurred at line: 38 in the jsp file: /TestChart.jsp
ChartRenderingInfo cannot be resolved to a type
35: chart.setBackgroundPaint(new Color(249, 231, 236));
36:
37: try {
38: final ChartRenderingInfo info = new ChartRenderingInfo
39: (new StandardEntityCollection());
40:
41: final File file1 = new File("..//Workspaces//TestJSP//WebContent//WEB-INF//areachart.png");


An error occurred at line: 39 in the jsp file: /TestChart.jsp
StandardEntityCollection cannot be resolved to a type
36:
37: try {
38: final ChartRenderingInfo info = new ChartRenderingInfo
39: (new StandardEntityCollection());
40:
41: final File file1 = new File("..//Workspaces//TestJSP//WebContent//WEB-INF//areachart.png");
42:


An error occurred at line: 43 in the jsp file: /TestChart.jsp
ChartUtilities cannot be resolved
40:
41: final File file1 = new File("..//Workspaces//TestJSP//WebContent//WEB-INF//areachart.png");
42:
43: ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);
44: } catch (Exception e) {
45: out.println(e);
46: }


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:589)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

-------------------------------

Please guide me
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

I believe, you may not have imported "all the relevant" classes.


S.D. MADHAN
Not many get the right opportunity !
 
GeeCON Prague 2014
 
subject: Charts In JSP