问题描述
刚学JFreeChart从网上找了实例但是碰到这样这样的问题希望高手指点谢谢代码:<%@pagecontentType="text/html;charset=GB2312"%><%@pageimport="org.jfree.chart.JFreeChart,org.jfree.chart.ChartUtilities,org.jfree.chart.ChartFactory,org.jfree.data.general.DefaultPieDataset,org.jfree.data.general.PieDataset,java.sql.*"%><html><body> <%Connectioncon=null;//数据连接对象Statementsql=null;//SQL语句对象ResultSetrs=null;//结果记录集对象StringdataName[]=newString[]{"","","",""};//显示数据系列intdataValueCount[]={0,0,0,0};//数据系列对应的值Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test","sa","12345");sql=con.createStatement();rs=sql.executeQuery("select'0-30岁'asuserage,count(*)asusercountfromuserTablewhereuser_age>=0anduser_age<30"+"unionselect'30-50岁'asuserage,count(*)asusercountfromuserTablewhereuser_age>=30anduser_age<50"+"unionselect'50-70岁'asuserage,count(*)asusercountfromuserTablewhereuser_age>=50anduser_age<70"+"unionselect'70岁以上'asuserage,count(*)asusercountfromuserTablewhereuser_age>=70");intj=0;while(rs.next()){dataName[j]=rs.getString("userage");dataValueCount[j]=rs.getInt("usercount");j++;}DefaultPieDatasetpieDataset=newDefaultPieDataset();for(inti=0;i<dataName.length;i++)pieDataset.setValue(dataName[i],dataValueCount[i]);StringtitleString="用户年龄阶段分布统计图";//图的标题JFreeChartchart=ChartFactory.createPieChart(titleString,pieDataset,true,true,false);ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,500,300);%></body></html>显示错误:exceptionorg.apache.jasper.JasperException:UnabletocompileclassforJSP:Anerroroccurredatline:35inthejspfile:/pie2.jspThemethodcreatePieChart(String,PieDataset,boolean,boolean,boolean)inthetypeChartFactoryisnotapplicableforthearguments(String,DefaultPieDataset,boolean,boolean,boolean)32:pieDataset.setValue(dataName[i],dataValueCount[i]);33:StringtitleString="用户年龄阶段分布统计图";//图的标题34:35:JFreeChartchart=ChartFactory.createPieChart(titleString,pieDataset,true,true,false);36:ChartUtilities.writeChartAsJPEG(response.getOutputStream(),chart,500,300);37:38:%>
解决方案
解决方案二:
代码中红色部分为错误行