<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.awt.*,java.text.SimpleDateFormat,javax.swing.JPanel,org.jfree.chart.ChartFactory,org.jfree.chart.ChartPanel,org.jfree.chart.JFreeChart,org.jfree.chart.axis.DateAxis,org.jfree.chart.plot.XYPlot,org.jfree.chart.renderer.xy.XYItemRenderer,org.jfree.chart.renderer.xy.XYLineAndShapeRenderer,org.jfree.data.time.*,org.jfree.data.time.TimeSeries,org.jfree.data.time.TimeSeriesCollection,org.jfree.data.xy.XYDataset"%>
<%@ page import="org.jfree.chart.servlet.ServletUtilities"%>
<%@ page import="org.jfree.data.general.DefaultPieDataset,org.jfree.data.general.PieDataset,org.jfree.chart.title.TextTitle,org.jfree.chart.plot.*,org.jfree.data.general.PieDataset" %>
<%@ page import="java.io.*,org.jfree.chart.ChartUtilities"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>我的實(shí)例</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<div align="center">
餅狀圖的實(shí)例--作者:Jacky yang. <br><br><br>
<%
String title = "空調(diào)2002年市場(chǎng)占有率";
//設(shè)定數(shù)據(jù)源
DefaultPieDataset piedata = new DefaultPieDataset();
//第一個(gè)參數(shù)為名稱,第二個(gè)參數(shù)是double數(shù)
piedata.setValue("聯(lián)想", 27.3);
piedata.setValue("長城", 12.2);
piedata.setValue("海爾", 5.5);
piedata.setValue("美的", 17.1);
piedata.setValue("松下", 9.0);
piedata.setValue("科龍", 14.0);
//創(chuàng)建JFreeChart,都使用ChartFactory來創(chuàng)建JFreeChart,很標(biāo)準(zhǔn)的工廠設(shè)計(jì)模式
JFreeChart chart =
ChartFactory.createPieChart(title, piedata, true, true, true);
//設(shè)定圖片標(biāo)題
chart.setTitle(new TextTitle(title, new Font("隸書", Font.ITALIC, 15)));
//chart.addSubtitle(new TextTitle("2002財(cái)年分析", new Font("隸書", Font.ITALIC, 12)));
//設(shè)定背景
chart.setBackgroundPaint(Color.white);
//chart.s
//餅圖使用一個(gè)PiePlot
PiePlot pie = (PiePlot)chart.getPlot();
//pie.setSectionLabelType(PiePlot.NAME_AND_PERCENT_LABELS);
//pie.setSectionLabelType(PiePlot.NAME_AND_VALUE_LABELS);
//設(shè)定顯示格式(名稱加百分比或數(shù)值)
//pie.setPercentFormatString("#,###0.0#%");
//設(shè)定百分比顯示格式
pie.setBackgroundPaint(Color.white);
//pie.setSectionLabelFont(new Font("黑體", Font.TRUETYPE_FONT, 12));
//設(shè)定背景透明度(0-1.0之間)
pie.setBackgroundAlpha(0.6f);
//設(shè)定前景透明度(0-1.0之間)
pie.setForegroundAlpha(0.90f);
//輸出文件到指定目錄
String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
//try {
//可以保存文件為jpg或png格式。
//ChartUtilities.saveChartAsJPEG(new File(fileName), 100, chart, 600, 600);
//第一個(gè)參數(shù)為文件名
//第二個(gè)參數(shù)質(zhì)量
//第三個(gè)參數(shù)為哪個(gè)chart創(chuàng)建圖片
//第四個(gè)寬度
//第五個(gè)高度
//}
//catch (IOException exz) {
// System.out.print("....Cant't Create image File");
// out.println(exz.getMessage());
//}
%>
<img src="<%=graphURL%>" border=0 usemap="#<%= filename %>">
</div>
</body>
</html>