java吧 关注:1,240,463贴子:12,712,575
  • 7回复贴,共1

有用过jfreechart做图表统计的么?有的话戳进,有问题请教

只看楼主收藏回复

我看书上写的jreechart程序,跟着写了个demo,但启动tomcat加载这个程序会报错,大神帮看下怎么回事
ChartUtils.java
package lee.utils;
import java.awt.Font;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;
public class ChartUtils {
private static PieDataset getDataset(){
DefaultPieDataset dataset=new DefaultPieDataset();
dataset.setValue("Java", 30);
dataset.setValue("C#", 25);
dataset.setValue("C++", 25);
dataset.setValue("PHP", 25);
dataset.setValue("C语言", 25);
return dataset;
}
public static JFreeChart createChart(){
StandardChartTheme standardChartTheme=new StandardChartTheme("CN");
standardChartTheme.setLargeFont(new Font("黑体", Font.BOLD , 16));
standardChartTheme.setRegularFont(new Font("宋体", Font.BOLD, 16));
standardChartTheme.setExtraLargeFont(new Font("隶书", Font.BOLD , 24));
ChartFactory.setChartTheme(standardChartTheme);
JFreeChart chart=ChartFactory.createPieChart3D("不同编程语言的市场占有率", getDataset(), true, true, true);
PiePlot plot=(PiePlot) chart.getPlot();
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}{2}",NumberFormat.getNumberInstance(),NumberFormat.getPercentInstance()));
plot.setBackgroundAlpha(0.8f);
plot.setForegroundAlpha(0.4f);
return chart;
}
}
index.jsp
<%@page import="lee.utils.ChartUtils"%>
<%@page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
<%
String fileName=ServletUtilities.saveChartAsJPEG(ChartUtils.createChart(), 450, 300, session);
String graphURL=request.getContextPath()+"/DisplayChart?filename="+fileName;
%>
<img alt="" src="<%=graphURL%>" border="1">
</body>
</html>


1楼2014-06-07 22:07回复
    Highcharts


    IP属地:加拿大2楼2014-06-07 22:12
    收起回复
      我用过,可以给你demo


      IP属地:上海来自Android客户端4楼2014-06-07 23:51
      收起回复