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.entity.*"%>
<%@ page import="org.jfree.data.general.*"%>

<%
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("JavaWorld", new Integer(75));
    pieDataset.setValue("Other", new Integer(25));
    JFreeChart chart = ChartFactory.createPieChart("Sample Pie Chart",pieDataset,true,true,false);
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Pie Chart</title>
</head>
<body>
    <IMG SRC="piechart.png" WIDTH="600" HEIGHT="400" BORDER="0"
        USEMAP="#chart">
</body>
</html>

为此,我使用 2 个 jar 文件

1.jfreechart-0.9.4.jar

2.jcommon-0.7.1.jar

但它抛出一个异常。

6 Jun, 2012 10:03:12 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 33 in the jsp file: /pages/pieChart.jsp
DefaultPieDataset cannot be resolved to a type
30:         out.println(e);
31: 
32:     } */
33:     DefaultPieDataset pieDataset = new DefaultPieDataset();
34:     pieDataset.setValue("JavaWorld", new Integer(75));
35:     pieDataset.setValue("Other", new Integer(25));
36:     JFreeChart chart = ChartFactory.createPieChart


An error occurred at line: 33 in the jsp file: /pages/pieChart.jsp
DefaultPieDataset cannot be resolved to a type
30:         out.println(e);
31: 
32:     } */
33:     DefaultPieDataset pieDataset = new DefaultPieDataset();
34:     pieDataset.setValue("JavaWorld", new Integer(75));
35:     pieDataset.setValue("Other", new Integer(25));
36:     JFreeChart chart = ChartFactory.createPieChart


Stacktrace:
    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
    at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
    at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:381)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.saveworks.application.AdminAuthenticationFilter.doFilter(AdminAuthenticationFilter.java:74)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)

请任何人可以帮助我?

提前致谢。

4

3 回答 3

0

1-你使用什么IDE

2-首先你应该尝试清理并构建然后运行

3-确保类路径类路径错误

4-您可能会以防万一将 jar 复制到 Apachetomcat lib 目录

5-如果一切正常,请确保您的库 jar 可能已损坏,因此请重新下载或未正确包含或根本不包含;确保将 jar 包含在其所有类中

我是这么想的,那么你应该看看这个,这些是专门为 Eclipse 准备的

链接到 jfreechart 教程

看教程

于 2012-06-06T04:56:38.133 回答
0

我更喜欢jqPlot。他们支持饼图。在此处查看演示。

这是一个免费的 jQuery 库,可让您创建与图像生成相比的交互式图表。

于 2012-06-06T05:58:25.123 回答
0

请在编译时检查您的DefaultPieDataset 类是否存在。

`DefaultPieDataset` cannot be resolved to a type
30:         out.println(e);

当 JSP 被编译为 servlet 时,需要解决编译时错误。那个时候,找不到这个类。检查你的 jar 文件这个类文件是否真的存在。

于 2012-06-06T04:51:25.467 回答