package com.xidian.servlet;
import java.awt.Color;
import java.awt.Font;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
/**
 * 生成饼状统计图
 * @说明 
 * @author fei.teng
 * @version 1.0
 * @since
 */
@SuppressWarnings("serial")
public class CakeServlet extends HttpServlet {
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		// 默认数据类型
		DefaultPieDataset dataType = new DefaultPieDataset();
		// 数据参数 内容,数量
		dataType.setValue("IE6", 156);
		dataType.setValue("IE7", 230);
		dataType.setValue("IE8", 45);
		dataType.setValue("火狐", 640);
		dataType.setValue("谷歌", 245);
		try {
			DefaultPieDataset data = dataType;
			// 生成普通饼状图除掉 3D 即可
			// 生产3D饼状图
			PiePlot3D plot = new PiePlot3D(data);
			JFreeChart chart = new JFreeChart(
					"用户使用的浏览器类型",            // 图形标题
					JFreeChart.DEFAULT_TITLE_FONT, // 标题字体
					plot,                          // 图标标题对象
					true                           // 是否显示图例
			);
			// 设置整个图片的背景色
			chart.setBackgroundPaint(Color.PINK);
			// 设置图片有边框
			chart.setBorderVisible(true);
			// 配置字体
			Font kfont = new Font("宋体", Font.PLAIN, 12);    // 底部
			Font titleFont = new Font("宋体", Font.BOLD, 25); // 图片标题
			// 图片标题
			chart.setTitle(new TextTitle(chart.getTitle().getText(), titleFont));
			// 底部
			chart.getLegend().setItemFont(kfont);
			ChartUtilities.writeChartAsJPEG(response.getOutputStream(), 1.0f,
					chart, 500, 300, null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
最近下载更多
嘉琪拉  LV2 2021年8月31日
wlxr1410  LV1 2021年6月7日
HUANG888  LV6 2021年2月18日
ITfans  LV19 2021年1月9日
15687890811  LV12 2020年7月1日
hxx88781143  LV8 2020年5月19日
zjjhzjb  LV14 2019年12月7日
wanglong_wang  LV13 2019年8月1日
Luis虎子  LV16 2019年6月26日
yp0416160222  LV2 2019年6月9日
最近浏览更多
fesfefe  LV13 2023年10月24日
getset  LV8 2022年12月6日
Tg171017  LV12 2022年11月30日
abc562311934  LV4 2022年10月8日
东北人  LV12 2022年9月20日
wusiyin  LV14 2022年9月15日
 LV7 2022年7月5日
heifenglei  LV7 2022年4月7日
yanliang2377912054 2021年12月22日
暂无贡献等级
梦里  LV3 2021年12月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友