javsjava或 jsp 实现柱状图,饼状图
高手请进 求java或 jsp 实现柱状图、饼状图源码
或调试通过以下源码均给分,下面源码session是怎么回事情
package bean;
import java.awt.Font;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
public class PieChart
{
//这个方法用来计算显示项数据所占比例
private double getRatio(HashMap map, Object value)
{
double result = 0.00;
double total = 0.00;
String strTemp = "";
Iterator iter = map.keySet().iterator();
while (iter.hasNext())
{
Object key = iter.next();
strTemp = (String) map.get(key);
total += (Double.parseDouble(strTemp));
}
strTemp = (String) map.get(value);
result = Double.parseDouble(strTemp) / total;
//result = (double) Math.round(result);
return result;
}
//创建绘制饼图
public String JCreate(HashMap map, String title, HttpSession session, int w,int h)
{
DefaultPieDataset piedata = new DefaultPieDataset();
//如果没有数据可以通过这一块来测试
piedata.setValue("Google", 130);
piedata.setValue("Baidu", 40.3);
piedata.setValue("sohu", 19.6);
// piedata.setValue("msn", 29.6);
Iterator iter = map.keySet().iterator();
while (iter.hasNext())
{
Object key = iter.next();
piedata.setValue(key.toString(), getRatio(map, key));
}
// 3D饼图
PiePlot3D plot = new PiePlot3D(piedata);
// 饼图
// PiePlot plot = new PiePlot(piedata);
// 设定链接 ("link.jsp","section"));//section为参数,不填写则默认为category
// plot.setURLGenerator(new StandardPieURLGenerator("link.jsp","section"));
// 指定图片的透明度
plot.setForegroundAlpha(1.0f);
plot.setDepthFactor(0.08);
// 指定显示的饼图上圆形(false)还椭圆形(true)
plot.setCircular(false);
// 显示百分比
plot.setLabelGenerator(new
StandardPieItemLabelGenerator(StandardPieItemLabelGenerator.DEFAULT_TOOLTIP_FORMAT));
plot.setLegendLabelGenerator(new StandardPieItemLabelGenerator("{0}:({1}M, {2})"));
JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot,true);
// 设置图片背景色
chart.setBackgroundPaint(java.awt.Color.white);
// 设置图片标题属性
Font font = new Font("黑体", Font.CENTER_BASELINE, 20);
TextTitle _title = new TextTitle(title);
_title.setFont(font);
chart.setTitle(_title);
plot.setToolTipGenerator(new StandardPieItemLabelGenerator());
// 把生成的图片放到临时目录
StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
String filename =