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.
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;
}
}
D:\Tomcat5\work\Catalina\localhost\_\org\apache\jsp\TMPdq4awvdlra_jsp.java:67: cannot resolve symbol
symbol : variable publicFun
location: class org.apache.jsp.TMPdq4awvdlra_jsp
dataset.addValue(rs.getFloat("totalSize"),"?块??㈢Н(骞虫?绫?)",publicFun.DisplayData(rs.getString("gxmc")));
^
An error occurred at line: 5 in the jsp file: /TMPdq4awvdlra.jsp
Generated servlet error:
D:\Tomcat5\work\Catalina\localhost\_\org\apache\jsp\TMPdq4awvdlra_jsp.java:68: cannot resolve symbol
symbol : variable publicFun
location: class org.apache.jsp.TMPdq4awvdlra_jsp
dataset.addValue(rs.getInt("num")*20,"?块???(??)",publicFun.DisplayData(rs.getString("gxmc")));
^
2 errors