急:jFreeChart的问题:不显示图,只显示个框
我看着书写了个jFreeChart小例子,不晓得哪儿做的不对,网页上总出不了图(实际上图已经出来了,我在tomcat/temp文件夹中找到了)
我将jcommon-1.0.10.jar\jfreechart-1.0.6.jar放到了WEB-INF的lib文件夹里。下面的是源文件内容:
jsp:(在工程的根目录下,即webroot下)
<%@ page contentType= "text/html;charset=GB2312 "%>
<%@ page import= "org.jfree.chart.ChartFactory,org.jfree.chart.JFreeChart,
org.jfree.chart.plot.PlotOrientation,org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.DefaultCategoryDataset,org.jfree.chart.ChartUtilities "
%>
<%
DefaultCategoryDataset dataset=new DefaultCategoryDataset();
dataset.addValue(300, "北京 ", "苹果 ");
dataset.addValue(200, "北京 ", "西瓜 ");
dataset.addValue(500, "北京 ", "葡萄 ");
dataset.addValue(340, "北京 ", "芒果 ");
dataset.addValue(280, "北京 ", "香蕉 ");
JFreeChart chart=ChartFactory.createBarChart3D( "水果销量统计图 ", "水果 ", "销量 ",dataset,PlotOrientation.VERTICAL,false,false,false);
String fileName=ServletUtilities.saveChartAsJPEG(chart,400,300,null,null);
String url=request.getContextPath()+ "/servelt/DisplayChart?filename= "+fileName;
%>
<html>
<head>
<title> JFreeChart Example </title>
</head>
<body>
<center>
<img src= " <%=url%> " border=1>
</center>
</body>
web.xml:
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app version= "2.4 "
xmlns= "http://java.sun.com/xml/ns/j2ee "
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<description> This is the description of my J2EE component </description>
<display-name> This is the display name of my J2EE component </display-name>
<servlet-name> DisplayChart </servlet-name>
<servlet-class> org.jfree.chart.servlet.DisplayChart </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> DisplayChart </servlet-name>
<url-pattern> /servlet/DisplayChart </url-pattern>
</servlet-mapping>
</web-app>
</html>
[解决办法]
图的位置放错了8 ,最好放到应用自己目录结构里(在应用的WebContent目录里)
[解决办法]
还真没看出来程序有什么问题,不过你可以下一个jfreechart-sample来试试。感觉你的配置跟例子里边的完全一样。
另:图的位置应该是没错的,这个是一个临时文件。