2 qq863017854 QQ863017854 于 2016.05.04 13:56 提问

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("","","",linedataset,PlotOrientation.VERTICAL,false,false,false);
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 report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 113 in the jsp file: /dingdanjieguo.jsp
The 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("","","",linedataset,PlotOrientation.VERTICAL,false,false,false);
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.jsp
The method setItemFont(Font) is undefined for the type Legend
114: 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)

1个回答

jia20003
jia20003   2016.05.04 15:10
已采纳

是你的Jasper Report的编译不通过,检查一个report的内容与格式,还有数据源等。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!