那位大虾能指点小弟使用jfreechat 我已经下载了jfreechat的压缩包现在就是不知道怎么下手,如果哪位兄弟有相关的使用说明文档还请与小弟共享一下 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最简单的例子<%@ page contentType="text/html;charset=GBK"%><%@ page import="org.jfree.chart.ChartFactory, org.jfree.chart.JFreeChart, org.jfree.chart.plot.PlotOrientation, org.jfree.chart.servlet.ServletUtilities, org.jfree.data.DefaultCategoryDataset"%><%DefaultCategoryDataset dataset = new DefaultCategoryDataset();dataset.addValue(300, "广州", "苹果");dataset.addValue(200, "广州", "梨子");dataset.addValue(500, "广州", "葡萄");dataset.addValue(340, "广州", "芒果");dataset.addValue(280, "广州", "荔枝");JFreeChart chart = ChartFactory.createBarChart3D("水果销量统计图", "水果", "销量", dataset, PlotOrientation.VERTICAL, false, false, false);String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;%><img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%= filename %>"> 不过这个不是应用JREECHART的正式版,但具体类功能都是一样的,正式版类变化 我提供一个柱状图的javabean(可执行,我在JSP中引用它),其它的参考自带的例子,熟练掌握它的API:import java.awt.Color;import java.io.FileOutputStream;import org.jfree.chart.ChartFactory;import org.jfree.chart.ChartUtilities;import org.jfree.chart.JFreeChart;import org.jfree.chart.axis.CategoryAxis;import org.jfree.chart.axis.ValueAxis;import org.jfree.chart.plot.CategoryPlot;import org.jfree.chart.plot.PlotOrientation;import org.jfree.chart.renderer.category.BarRenderer3D;import org.jfree.data.category.CategoryDataset;import org.jfree.data.general.DatasetUtilities;public class JFreeBarBean { private String title; private String rowName; private String columnName; private boolean showValue = true; private Color backColor = Color.WHITE; private Color lineColor = Color.BLACK; private Color wallColor = Color.GRAY; private double[][] data; private String[] rowKeys; private String[] columnKeys; private double upperMargin = 0.15; private double lowerMargin = 0.15; public JFreeChart createChart() { CategoryDataset dataset = DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data); JFreeChart chart = ChartFactory.createBarChart3D( title, rowName, columnName, dataset, PlotOrientation.VERTICAL, true, false, false); chart.setBackgroundPaint(backColor); CategoryPlot plot = chart.getCategoryPlot(); CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setVerticalCategoryLabels(false); plot.setDomainAxis(domainAxis); ValueAxis rangeAxis = plot.getRangeAxis(); // 设置最高的一个 Item 与图片顶端的距离 rangeAxis.setUpperMargin(upperMargin); // 设置最低的一个 Item 与图片底端的距离 rangeAxis.setLowerMargin(lowerMargin); plot.setRangeAxis(rangeAxis); BarRenderer3D renderer = new BarRenderer3D(); renderer.setBaseOutlinePaint(lineColor); // 设置 Wall 的颜色 renderer.setWallPaint(wallColor); // renderer.setItemMargin(0.1); // 显示每个柱的数值,并修改该数值的字体属性 renderer.setItemLabelsVisible(showValue); plot.setRenderer(renderer); // 设置柱的透明度 plot.setForegroundAlpha(0.8f); return chart; } public JFreeBarBean( double[][] datas, String[] row, String[] column, String name, String rowName, String columnName) { this.data = datas; this.rowKeys = row; this.columnKeys = column; this.title = name; this.rowName = rowName; this.columnName = columnName; } public JFreeBarBean(double[][] datas, String[] row, String[] column) { this.data = datas; this.rowKeys = row; this.columnKeys = column; this.title = ""; this.rowName = ""; this.columnName = ""; } public void showChart() { try { FileOutputStream out = new FileOutputStream("D:\\fruit5.jpg"); ChartUtilities.writeChartAsJPEG(out, 100, createChart(), 400, 300); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { double[][] data = new double[][] { { 672, 766, 223, 540, 126 }, { 325, 521, 210, 340, 106 }, { 332, 256, 523, 240, 526 } }; String[] rowKeys = { "苹果", "梨子", "葡萄" }; String[] columnKeys = { "北京", "上海", "广州", "成都", "深圳" }; JFreeBarBean bean = new JFreeBarBean( data, rowKeys, columnKeys, "Fruit chart", "Fruit", "Produce"); bean.showChart(); } /** * @return */ public Color getBackColor() { return backColor; } /** * @return */ public String[] getColumnKeys() { return columnKeys; } /** * @return */ public String getColumnName() { return columnName; } /** * @return */ public double[][] getData() { return data; } /** * @return */ public Color getLineColor() { return lineColor; } /** * @return */ public double getLowerMargin() { return lowerMargin; } /** * @return */ public String[] getRowKeys() { return rowKeys; } /** * @return */ public String getRowName() { return rowName; } /** * @return */ public boolean isShowValue() { return showValue; } /** * @return */ public String getTitle() { return title; } /** * @return */ public double getUpperMargin() { return upperMargin; } /** * @return */ public Color getWallColor() { return wallColor; } /** * @param color */ public void setBackColor(Color color) { backColor = color; } /** * @param strings */ public void setColumnKeys(String[] strings) { columnKeys = strings; } /** * @param string */ public void setColumnName(String string) { columnName = string; } /** * @param ds */ public void setData(double[][] ds) { data = ds; } /** * @param color */ public void setLineColor(Color color) { lineColor = color; } /** * @param d */ public void setLowerMargin(double d) { lowerMargin = d; } /** * @param strings */ public void setRowKeys(String[] strings) { rowKeys = strings; } /** * @param string */ public void setRowName(String string) { rowName = string; } /** * @param b */ public void setShowValue(boolean b) { showValue = b; } /** * @param string */ public void setTitle(String string) { title = string; } /** * @param d */ public void setUpperMargin(double d) { upperMargin = d; } /** * @param color */ public void setWallColor(Color color) { wallColor = color; }} 一个java服务问题 关于用JAVA发mail的问题,请高手帮助 如何配制ant? struts+hibernate+spring中的一个问题(给分) 如何提高自己学习JAVA编程????? hibernate问题 有关xdoclet的,问问 有不懂STRUTS的吗??公布第一次学习STRUTS的经验 在JBuilder 6 中如何将Bean代码打包成Jar文件? 请问JAVA虚拟机是什么东西 java运行程序不成功? 怎样用正则批配中文字串
<%@ page import="org.jfree.chart.ChartFactory,
org.jfree.chart.JFreeChart,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.DefaultCategoryDataset"%>
<%
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(300, "广州", "苹果");
dataset.addValue(200, "广州", "梨子");
dataset.addValue(500, "广州", "葡萄");
dataset.addValue(340, "广州", "芒果");
dataset.addValue(280, "广州", "荔枝");JFreeChart chart = ChartFactory.createBarChart3D("水果销量统计图",
"水果",
"销量",
dataset,
PlotOrientation.VERTICAL,
false,
false,
false);String filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
%>
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%= filename %>"> 不过这个不是应用JREECHART的正式版,但具体类功能都是一样的,正式版类变化
import java.awt.Color;
import java.io.FileOutputStream;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer3D;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.general.DatasetUtilities;
public class JFreeBarBean {
private String title;
private String rowName;
private String columnName;
private boolean showValue = true;
private Color backColor = Color.WHITE;
private Color lineColor = Color.BLACK;
private Color wallColor = Color.GRAY;
private double[][] data;
private String[] rowKeys;
private String[] columnKeys;
private double upperMargin = 0.15;
private double lowerMargin = 0.15;
public JFreeChart createChart() {
CategoryDataset dataset =
DatasetUtilities.createCategoryDataset(rowKeys, columnKeys, data);
JFreeChart chart =
ChartFactory.createBarChart3D(
title,
rowName,
columnName,
dataset,
PlotOrientation.VERTICAL,
true,
false,
false);
chart.setBackgroundPaint(backColor);
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setVerticalCategoryLabels(false);
plot.setDomainAxis(domainAxis);
ValueAxis rangeAxis = plot.getRangeAxis();
// 设置最高的一个 Item 与图片顶端的距离
rangeAxis.setUpperMargin(upperMargin);
// 设置最低的一个 Item 与图片底端的距离
rangeAxis.setLowerMargin(lowerMargin);
plot.setRangeAxis(rangeAxis);
BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(lineColor);
// 设置 Wall 的颜色
renderer.setWallPaint(wallColor);
//
renderer.setItemMargin(0.1);
// 显示每个柱的数值,并修改该数值的字体属性
renderer.setItemLabelsVisible(showValue);
plot.setRenderer(renderer);
// 设置柱的透明度
plot.setForegroundAlpha(0.8f);
return chart;
}
public JFreeBarBean(
double[][] datas,
String[] row,
String[] column,
String name,
String rowName,
String columnName) {
this.data = datas;
this.rowKeys = row;
this.columnKeys = column;
this.title = name;
this.rowName = rowName;
this.columnName = columnName;
}
public JFreeBarBean(double[][] datas, String[] row, String[] column) {
this.data = datas;
this.rowKeys = row;
this.columnKeys = column;
this.title = "";
this.rowName = "";
this.columnName = "";
}
public void showChart() {
try {
FileOutputStream out = new FileOutputStream("D:\\fruit5.jpg");
ChartUtilities.writeChartAsJPEG(out, 100, createChart(), 400, 300);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
double[][] data = new double[][] { { 672, 766, 223, 540, 126 }, {
325, 521, 210, 340, 106 }, {
332, 256, 523, 240, 526 }
};
String[] rowKeys = { "苹果", "梨子", "葡萄" };
String[] columnKeys = { "北京", "上海", "广州", "成都", "深圳" };
JFreeBarBean bean =
new JFreeBarBean(
data,
rowKeys,
columnKeys,
"Fruit chart",
"Fruit",
"Produce");
bean.showChart();
}
/**
* @return
*/
public Color getBackColor() {
return backColor;
}
/**
* @return
*/
public String[] getColumnKeys() {
return columnKeys;
}
/**
* @return
*/
public String getColumnName() {
return columnName;
}
/**
* @return
*/
public double[][] getData() {
return data;
}
/**
* @return
*/
public Color getLineColor() {
return lineColor;
}
/**
* @return
*/
public double getLowerMargin() {
return lowerMargin;
}
/**
* @return
*/
public String[] getRowKeys() {
return rowKeys;
}
/**
* @return
*/
public String getRowName() {
return rowName;
}
/**
* @return
*/
public boolean isShowValue() {
return showValue;
}
/**
* @return
*/
public String getTitle() {
return title;
}
/**
* @return
*/
public double getUpperMargin() {
return upperMargin;
}
/**
* @return
*/
public Color getWallColor() {
return wallColor;
}
/**
* @param color
*/
public void setBackColor(Color color) {
backColor = color;
}
/**
* @param strings
*/
public void setColumnKeys(String[] strings) {
columnKeys = strings;
}
/**
* @param string
*/
public void setColumnName(String string) {
columnName = string;
}
/**
* @param ds
*/
public void setData(double[][] ds) {
data = ds;
}
/**
* @param color
*/
public void setLineColor(Color color) {
lineColor = color;
}
/**
* @param d
*/
public void setLowerMargin(double d) {
lowerMargin = d;
}
/**
* @param strings
*/
public void setRowKeys(String[] strings) {
rowKeys = strings;
}
/**
* @param string
*/
public void setRowName(String string) {
rowName = string;
}
/**
* @param b
*/
public void setShowValue(boolean b) {
showValue = b;
}
/**
* @param string
*/
public void setTitle(String string) {
title = string;
}
/**
* @param d
*/
public void setUpperMargin(double d) {
upperMargin = d;
}
/**
* @param color
*/
public void setWallColor(Color color) {
wallColor = color;
}
}