图形报表送分(2)

feilong816 2004-10-12 09:09:32
http://community.csdn.net/Expert/topic/3429/3429083.xml?temp=.9835932贴的
xxlcg(☆突突☆) 进来领分
...全文
153 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fancard 2004-11-24
  • 打赏
  • 举报
回复
好啊!!
shiyonggang 2004-11-24
  • 打赏
  • 举报
回复
good up
zyp123 2004-11-24
  • 打赏
  • 举报
回复
good
catblue 2004-11-24
  • 打赏
  • 举报
回复
学习来的
catblue 2004-11-23
  • 打赏
  • 举报
回复
接分呀。
wandou999 2004-11-22
  • 打赏
  • 举报
回复
up
jimaojian 2004-11-15
  • 打赏
  • 举报
回复
WebChart.java

package net.sentom.chart;

import java.awt.Insets;
import java.awt.Color;
import java.awt.Font;
import java.awt.BasicStroke;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.entity.*;
import org.jfree.chart.urls.*;
import org.jfree.chart.servlet.*;
import org.jfree.chart.labels.StandardPieToolTipGenerator;


public class WebChart {
private DefaultPieDataset data = new DefaultPieDataset();

public void setValue(String key,double value){
data.setValue(key,value);
}

public String generatePieChart(String title, HttpSession session, PrintWriter pw) {
String filename = null;
try {
JFreeChart chart = ChartFactory.createPieChart("饼型图", // chart title
data, // data
true, // include legend
true,
false
);
//设置图片的背景色
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);
//chart.setAntiAlias(false);

PiePlot plot = (PiePlot) chart.getPlot();
plot.setInsets(new Insets(5, 5, 5, 5));
//在统计图片上建连结
plot.setURLGenerator(new StandardPieURLGenerator("link.jsp","section"));
//指定 section 标签的的类型
plot.setSectionLabelType(PiePlot.NAME_AND_VALUE_LABELS);
//指定 section 轮廓线的颜色
plot.setDefaultOutlinePaint(new Color(0x99, 0x99, 0xFF));
//指定 section 轮廓线的厚度
plot.setDefaultOutlineStroke(new BasicStroke(0));
plot.setRadius(0.70);
//抽离一个 section 出来
plot.setExplodePercent(1, 1.00);
//设置第一个 section 的开始位置,默认是12点钟方向
plot.setStartAngle(270);
//指定 section 的色彩
plot.setPaint(1, new Color(0x99, 0x99, 0xFF));
//指定 section 按逆时针方向依次显示,默认是顺时针方向
plot.setDirection(PiePlot.ANTICLOCKWISE);
//指定显示的饼图上圆形还椭圆形
//plot.setCircular(false);
plot.setToolTipGenerator(new StandardPieToolTipGenerator());

//把生成的图片放到临时目录
ChartRenderingInfo info = new ChartRenderingInfo(new

StandardEntityCollection());
//500是图片长度,300是图片高度
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info,

session);

ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();

} catch (Exception e) {
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
}


pie.jsp <%@ page contentType="text/html;charset=GBK"%>
<%@ page import = "java.io.PrintWriter" %>
<%@ page import="net.sentom.chart.WebChart"%>
<%
WebChart chart = new WebChart();
chart.setValue("六月",500);
chart.setValue("七月",580);
chart.setValue("八月",828);
chart.setValue("九月",928);
chart.setValue("十月",1028);

String filename = chart.generatePieChart("www.SenTom.net 网站日均访问统计表", session, new

PrintWriter(out));
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<HTML>
<HEAD>
<TITLE>www.sentom.net</TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%=

filename %>">
</P>
</BODY>
</HTML>
</BODY>
</HTML>

运行结果如下:




二 org.jfree.chart.plot.Pie3DPlot

使用该类指定 3D 饼形图的属性。Pie3DPlot 是上面讲到的 PiePlot 的子类,所以呢,上面介绍的的方法 在 Pie3DPlot 中都适用。这里不在重复,只介绍一个上面没有介绍的 setForegroundAlpha(float alpha) 方 法,设置图片的透明度。

对上面 WebChar.java 程序做一点改动:


/*
* Created on 2003-9-9
* http://www.sentom.net
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package net.sentom.chart;

import java.awt.Insets;
import java.awt.Color;
import java.awt.Font;
import java.awt.BasicStroke;
import java.io.PrintWriter;
import javax.servlet.http.HttpSession;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.entity.*;
import org.jfree.chart.urls.*;
import org.jfree.chart.servlet.*;
import org.jfree.chart.labels.StandardPieToolTipGenerator;

/**
* @author sentom
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class WebChart {
private DefaultPieDataset data = new DefaultPieDataset();

public void setValue(String key,double value){
data.setValue(key,value);
}

public String generatePieChart(String title, HttpSession session, PrintWriter pw) {
String filename = null;
try {
JFreeChart chart = ChartFactory.createPie3DChart("饼型图", // chart title
data, // data
true, // include legend
true,
false
);
//设置图片的背景色
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);
//chart.setAntiAlias(false);

PiePlot plot = (PiePlot) chart.getPlot();
plot.setInsets(new Insets(5, 5, 5, 5));
//在统计图片上建连结
plot.setURLGenerator(new StandardPieURLGenerator("link.jsp","section"));
//指定 section 标签的的类型
plot.setSectionLabelType(PiePlot.NAME_LABELS);
//指定 section 轮廓线的颜色
plot.setDefaultOutlinePaint(null);
//指定 section 轮廓线的厚度
plot.setDefaultOutlineStroke(new BasicStroke(0));
//设置第一个 section 的开始位置,默认是12点钟方向
plot.setStartAngle(270);
//指定 section 的色彩
plot.setPaint(1, new Color(0x99, 0x99, 0xFF));
//指定 section 按逆时针方向依次显示,默认是顺时针方向
plot.setDirection(PiePlot.ANTICLOCKWISE);
//指定显示的饼图上圆形还椭圆形
//plot.setCircular(false);
plot.setToolTipGenerator(new StandardPieToolTipGenerator());
//指定图片的透明度
plot.setForegroundAlpha(0.5f);

//把生成的图片放到临时目录
ChartRenderingInfo info = new ChartRenderingInfo(new

StandardEntityCollection());
//500是图片长度,300是图片高度
filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info,

session);

ChartUtilities.writeImageMap(pw, filename, info);
pw.flush();

} catch (Exception e) {
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_500x300.png";
}
return filename;
}
}


jlpdgy004 2004-10-27
  • 打赏
  • 举报
回复
UP

DING
loverisyour 2004-10-27
  • 打赏
  • 举报
回复
又点名拉,楼主分真多
wandou999 2004-10-19
  • 打赏
  • 举报
回复
uuuuuuuuuup

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧