jasper / jfreechart异常错误

时间:2012-10-29 17:20:35

标签: java apache jsp jfreechart

我对网络开发真的很陌生......我试图在JSP上绘制区域图(这是练习版..如果我需要制作从数据库中读取数据的程序),当我尝试运行代码时出现以下错误,我不知道如何解决这个问题...... :(

 <%@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[][]{
  {110, 200, 220, 165, 199},
  {100, 204, 101, 101, 240}
  };

 final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Box", "ape", 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());

     String root = getServletContext().getRealPath("/");
   String path = root + "\\" + "areachart.png";

 final File file1 = new File(path);

 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 SRC="areachart.png" WIDTH="600" HEIGHT="400" BORDER="0" USEMAP="#chart">
  </body>
</html> 

错误:

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

An error occurred at line: 31 in the jsp file: /graph.jsp
The method createAreaChart(String, String, String, CategoryDataset, boolean, boolean, boolean) in the type ChartFactory is not applicable for the arguments (String, String, String, CategoryDataset, PlotOrientation, boolean, boolean, boolean)
28: 
29:  final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Box", "ape", data);
30: 
31:  final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", "", "Value", dataset, PlotOrientation.VERTICAL,true, true, false);
32: 
33:  final CategoryPlot plot = chart.getCategoryPlot();
34:  plot.setForegroundAlpha(0.5f);


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

提前致谢!

编辑:

如果我删除PlotOrientation.VERTICAL ..我得到这个错误是一样的吗? ; /我不确定我做错了什么:(

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

An error occurred at line: 31 in the jsp file: /graph.jsp
The method createAreaChart(String, String, String, CategoryDataset, boolean, boolean, boolean) in the type ChartFactory is not applicable for the arguments (String, String, String, CategoryDataset, boolean, boolean, boolean)
28: 
29:  final CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Box", "ape", data);
30: 
31:  final JFreeChart chart = ChartFactory.createAreaChart("Area Chart", "", "Value",dataset,true, true, false);
32: 
33:  final CategoryPlot plot = chart.getCategoryPlot();
34:  plot.setForegroundAlpha(0.5f);


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:102)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:331)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:469)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:378)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:646)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

1 个答案:

答案 0 :(得分:1)

如果查看错误,则传递的参数数量错误。你传递的内容如下:

(String, String, String, CategoryDataset, PlotOrientation, boolean, boolean, boolean)

期待以下参数:

(String, String, String, CategoryDataset, boolean, boolean, boolean)

删除PlotOrientation,它应该摆脱该错误。