📄 jpie.jsp
字号:
<!--
Fig. 8.2_07: jPie.jsp
功能: JFreeChart实例7: 普通默认饼图
-->
<%@ page language="java" contentType="image/png;charset=GB2312"
import="org.jfree.chart.*"
import="org.jfree.chart.servlet.*"
import="org.jfree.chart.plot.*"
import="org.jfree.chart.renderer.*"
import="org.jfree.chart.entity.*"
import="org.jfree.data.*"
import="org.jfree.data.general.*"
%>
<%!
String bookTitle[] = {"Python", "JAVA", "C#", "Perl", "PHP"};
String chartTitle = "JFreeChart实例7: 编程类图书周销售量普通饼图";
// 创建数据集
public PieDataset createDataset()
{
DefaultPieDataset dataset = new DefaultPieDataset();
for (int i = 0; i < bookTitle.length; i++)
{
dataset.setValue(bookTitle[i], (int)(10 + Math.random()* 40));
}
return dataset;
}
public JFreeChart createChart(PieDataset dataset)
{
JFreeChart chart = ChartFactory.createPieChart
(
chartTitle, // 图表标题
dataset, // 数据集
true, // 定义图例
true,
false
);
return chart;
}
%>
<%
// 创建一个 500X375 的图像
int width=500, height=375;
PieDataset dataset = createDataset();
JFreeChart chart = createChart(dataset);
ChartRenderingInfo info =
new ChartRenderingInfo(new StandardEntityCollection());
// 设置图片生成格式
String fileName =
ServletUtilities.saveChartAsPNG(chart, width, height, info, session);
// 设置图片生成路径
String graphURL =
request.getContextPath() + "/servlet/DisplayChart?filename=" + fileName;
%>
<HTML>
<HEAD>
<TITLE><%=chartTitle%></TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%=graphURL %>" border="1" >
</P>
</BODY>
</HTML>
<%
/**************************************************************************
* (C) Copyright 2004-2005 by Jingkui Zhong(钟京馗) and Huan Tang(唐桓). *
* All Rights Reserved. *
* *
* DISCLAIMER: The authors of this code have used their *
* best efforts in preparing the code. These efforts include the *
* development, research, and testing of the theories and programs *
* to determine their effectiveness. The authors and publisher make *
* no warranty of any kind, expressed or implied, with regard to these *
* programs or to the documentation contained in these codes. The authors *
* shall not be liable in any event for incidental or consequential *
* damages in connection with, or arising out of, the furnishing, *
* performance, or use of these programs. *
**************************************************************************/
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -