0

我对网络开发真的很陌生...我正在尝试在 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)
4

1 回答 1

1

如果您查看错误,则您传递的参数数量错误。您正在传递以下内容:

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

它期待以下参数:

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

删除PlotOrientation它应该可以消除该错误。

于 2012-10-29T17:28:18.110 回答