有没有人有JFreeChart Developer Guide?
解决方案 »
- 请问谁有孔庆贺教师的《基于STRUTS2的信息发布系统项目实战》代码?
- 使用fineReport后tomcat内存只增不减
- 关于线程间的通信
- jquery分装了对form对象操作?
- javamail在发送时候的信息能不能记录下来?
- hql 总出错 帮我看看
- 购物车问题(在线等答案)
- 我想使用j2ee做一个网站,然后部分内容要与一个windows程序进行数据调用。
- weblogic+jbuilder2005如何单步调试EJB,有文档,请高手翻译一下
- 某些文件只能放在tomcat\bin 下面?
- 一个很简单的小问题,关于applet的显示
- Struts--<html:link>标签如何在另一个页面接收对象参数呀!
解压缩后应该有个jfreechart-0.9.11-demo.jar
运行: java -jar jfreechart-0.9.11-demo.jar 就可以启动实例的主程序另外在org.jfree.chart.demo 下有数十个例子,和主程序不重复,均以****Demo*.java命名,并且均可独立运行。
package demo;import java.io.*;import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
/**
* 该类用于演示最简单的柱状图生成
* @author Winter Lau
*/
public class BarChartDemo
{
public static void createChart() throws IOException
{
CategoryDataset dataset = getDataSet2();
/*
public abstract class ChartFactory extends java.lang.Object
A collection of utility methods for creating some standard charts with JFreeChart.
*/
JFreeChart chart = ChartFactory.createBarChart3D(
"水果产量图", // 图表标题
"水果", // 目录轴的显示标签
"产量", // 数值轴的显示标签
dataset, // 数据集
PlotOrientation.VERTICAL, // 图表方向:水平、垂直
true, // 是否显示图例(对于简单的柱状图必须是false)
false, // 是否生成工具
false // 是否生成URL链接
);
FileOutputStream fos_jpg = null;
try {
fos_jpg = new FileOutputStream("D:\\fruit.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,400,300,null);
/*public class ChartUtilities extends java.lang.Object
Utility methods for JFreeChart.
包含JFreeChart的所有方法
Includes methods for converting charts to image formats (PNG and JPEG) plus creating simple HTML image maps.
包括将图表转换成图像的方法,创建简单的HTML图像管理分析与规划系统
*/
/*writeChartAsJPEG
public static void writeChartAsJPEG(
java.io.OutputStream out,//输出的字节流
JFreeChart chart, //图表
int width, //生成图片的宽度
int height, //生成图片的高度
ChartRenderingInfo info //图表信息
)
throws java.io.IOException
Writes the chart to the output stream in JPEG format.
输出图表到图片格式的字节流
This method allows you to pass in a ChartRenderingInfo object, to collect information about the chart dimensions/entities.
这个方法允许你传递一个图表表现对象,收集图表的尺度实体信息
You will need this info if you want to create an HTML image map.
你将需要这些信息创建一个HTML图像图 Parameters:
out - the output stream.
chart - the chart.
width - the image width.
height - the image height.
info - the chart rendering info.
Throws:
java.io.IOException - if there are any I/O errors. */
}
finally
{
try {
fos_jpg.close();
} catch (Exception e) {}
}
}
private static CategoryDataset getDataSet2()
{
/*public interface CategoryDataset extends KeyedValues2D, Dataset The interface for a dataset with one or more series, and values associated with categories.
一个或多个系列的数据接口,数据值与某一种类关联
The categories are represented by Comparable instance, with the category label being provided by the toString method.
*/
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
//创建一个新的dataset
/*public interface Dataset
The base interface for data sets. All datasets are required to support the DatasetChangeEvent mechanism by allowing listeners to register and receive notification of any changes to the dataset.
所有数据设置必须支持数据变化事件机制被允许监听记录和接收所有变化数据的通知
In addition, all datasets must belong to one (and only one) DatasetGroup.
用增加方法所有的设置必须一个只有一个数据组。
The group object maintains a reader-writer lock which provides synchronised access to the datasets in multi-threaded code.
这个组对象维持读与写的锁,规定同时数据设置的使用权的多线程代码
*/
dataset.addValue(100, "北京", "苹果");
dataset.addValue(100, "上海", "苹果");
dataset.addValue(100, "广州", "苹果");
dataset.addValue(200, "北京", "梨子");
dataset.addValue(200, "上海", "梨子");
dataset.addValue(200, "广州", "梨子");
dataset.addValue(300, "北京", "葡萄");
dataset.addValue(300, "上海", "葡萄");
dataset.addValue(null, "广州", "葡萄");
dataset.addValue(400, "北京", "香蕉");
dataset.addValue(400, "上海", "香蕉");
dataset.addValue(400, "广州", "香蕉");
dataset.addValue(500, "北京", "荔枝");
dataset.addValue(500, "上海", "荔枝");
dataset.addValue(500, "广州", "荔枝");
return dataset;
}
}上面的文件编译成BarChartDemo.class做成bean
引用bean的JSP文件
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.util.*"%>
<jsp:useBean id="create" scope="page" class="demo.BarChartDemo"/>
<html>
<head><title>createChart</title>
<body>
<%
create.createChart();
%>
<INPUT TYPE="image" SRC="D:\fruit.jpg">
</body>
</html>