我已经下载了jfreechat的压缩包
现在就是不知道怎么下手,如果哪位兄弟有相关的使用说明文档
还请与小弟共享一下

解决方案 »

  1.   

    最简单的例子<%@ 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的正式版,但具体类功能都是一样的,正式版类变化
      

  2.   

    我提供一个柱状图的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;
    }
    }