2
我嘗試使用這段代碼,但是出現錯誤。該代碼在java項目中工作,但不工作時,我將它添加到jsp文件<% grafik.ciz()%>
這樣。JSP中的JFreeChart錯誤
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文件。我該如何解決它?
哦非常感謝。我怎樣才能動態地做到這一點?我必須寫servlet? – user1545283
@ user1545283:請參閱此[備選](http://stackoverflow.com/a/13093044/230513)。 – trashgod