JSP中的JFreeChart错误

时间:2012-10-27 20:12:39

标签: jsp jfreechart

我尝试使用此代码但我犯了一个错误。该代码适用于java项目,但是当我将它添加到jsp文件<% grafik.ciz()%>时不起作用。

  package yazlab;

import java.awt.*;
import java.io.*;
import org.jfree.chart.*;
import org.jfree.chart.axis.*;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.category.*;
import org.jfree.data.category.*;
import org.jfree.data.general.*;


public class grafik
{

public static void ciz()
{
      final DefaultPieDataset data = new DefaultPieDataset();
      data.setValue("One", new Double(43.2));
      data.setValue("Two", new Double(10.0));
      data.setValue("Three", new Double(27.5));
      data.setValue("Four", new Double(17.5));
      data.setValue("Five", new Double(11.0));
      data.setValue("Six", new Double(19.4));

      JFreeChart chart = ChartFactory.createPieChart
      ("Pie Chart ", data, true, true, false);

     try
     {
         final ChartRenderingInfo info = new 
         ChartRenderingInfo(new StandardEntityCollection());
          final File file1 = new File("C:\\Users\\Lycanthrope\\Desktop\\piechart.png");
          ChartUtilities.saveChartAsPNG(
           file1, chart, 600, 400, info);
      } 
     catch (Exception e)
     {
      System.out.println(e);
     }
}
}

org.apache.jasper.JasperException。我在项目jcommon和jfreechart中添加了两个.jar文件。我该如何解决?

1 个答案:

答案 0 :(得分:0)

尝试将图表图像路径放在jsp

<div class="chartimage">
<img src="C:/Users/Lycanthrope/Desktop/piechart.png" height="500px" width="500px"/>
</div>