问题描述
- jsp 中用jfreechart 运行出错 求大神解答 或求折线例子
- 代码如下
DefaultCategoryDataset linedataset = new DefaultCategoryDataset();// 各曲线名称String series1 = ""订单量与时间"";String series2 = ""发生金额与时间""; // DefaultCategoryDataset dataset = new DefaultCategoryDataset(); while(rs.next()){ // dataset.addValue(rs.getInt(2)rs.getDate(1) ""); linedataset.addValue(rs.getInt(2) series1 rs.getDate(1)); linedataset.addValue(rs.getInt(3) series2 rs.getDate(1)); num=num+rs.getInt(2); money=money+rs.getFloat(3); %> <tr> <td width=45% align=""center""><%out.print(rs.getDate(1));%></td> <td width=30% align=""center""><%out.print(rs.getInt(2));%></td> <td width=30% align=""center""><%out.print(rs.getFloat(3));%></td> </tr> <% } //定义图表对象JFreeChart chart = ChartFactory.createLineChart(""""""linedatasetPlotOrientation.VERTICALfalsefalsefalse);CategoryPlot plot = chart.getCategoryPlot();/*字体乱码异常解决代码*/chart.getTitle().setFont(new Font(""宋体"" Font.BOLD 15)); chart.getLegend().setItemFont(new Font(""黑体"" Font.BOLD 15)); CategoryAxis domainAxis = plot.getDomainAxis(); /*------设置X轴坐标上的文字-----------*/ domainAxis.setTickLabelFont(new Font(""黑体"" Font.PLAIN 11)); /*------设置X轴的标题文字------------*/ domainAxis.setLabelFont(new Font(""宋体"" Font.PLAIN 12)); NumberAxis numberaxis = (NumberAxis) plot.getRangeAxis(); /*------设置Y轴坐标上的文字-----------*/ numberaxis.setTickLabelFont(new Font(""黑体"" Font.PLAIN 12)); /*------设置Y轴的标题文字------------*/ numberaxis.setLabelFont(new Font(""黑体"" Font.PLAIN 12));/*字体乱码异常解决代码*/ // 各种属性设置...NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());rangeAxis.setAutoRangeIncludesZero(true);rangeAxis.setUpperMargin(0.20);rangeAxis.setLabelAngle(Math.PI / 2.0); //String filename = ServletUtilities.saveChartAsPNG(chart 500 300 null session);String graphURL = request.getContextPath() + ""/DisplayChart?filename="" + filename;
HTTP Status 500 -type Exception reportmessagedescription The server encountered an internal error () that prevented it from fulfilling this request.exceptionorg.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 113 in the jsp file: /dingdanjieguo.jspThe method createLineChart(String String String CategoryDataset PlotOrientation boolean boolean boolean) in the type ChartFactory is not applicable for the arguments (String String String DefaultCategoryDataset PlotOrientation boolean boolean boolean)110: <% 111: } 112: //瀹氫箟鍥捐〃瀵硅薄113: JFreeChart chart = ChartFactory.createLineChart(""""""linedatasetPlotOrientation.VERTICALfalsefalsefalse);114: CategoryPlot plot = chart.getCategoryPlot();115: /*瀛椾綋涔辩爜寮傚父瑙e喅浠g爜*/116: chart.getTitle().setFont(new Font(""瀹嬩綋"" Font.BOLD 15));An error occurred at line: 117 in the jsp file: /dingdanjieguo.jspThe method setItemFont(Font) is undefined for the type Legend114: CategoryPlot plot = chart.getCategoryPlot();115: /*瀛椾綋涔辩爜寮傚父瑙e喅浠g爜*/116: chart.getTitle().setFont(new Font(""瀹嬩綋"" Font.BOLD 15));117: chart.getLegend().setItemFont(new Font(""榛戜綋"" Font.BOLD 15));118: CategoryAxis domainAxis = plot.getDomainAxis(); 119: /*------璁剧疆X杞村潗鏍囦笂鐨勬枃瀛?----------*/ 120: domainAxis.setTickLabelFont(new Font(""榛戜綋"" Font.PLAIN 11)); Stacktrace: org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:423) org.apache.jasper.compiler.Compiler.compile(Compiler.java:308) org.apache.jasper.compiler.Compiler.compile(Compiler.java:286) org.apache.jasper.compiler.Compiler.compile(Compiler.java:273) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
解决方案
是你的Jasper Report的编译不通过,检查一个report的内容与格式,还有数据源等。
时间: 2024-10-29 17:23:39