下载了jfreechart后,将jfreechart-0.9.6.zip下载后解压,然后将jfreechart-0.9.6.jar和lib里面的jcommon-0.7.2.jar两个文件加入到Classpath中,接着就可以利用jfreechart进行开发了。 你可以自己看一下里面的demo,不是很难! good luck!
/* ====================================== * JFreeChart : a free Java chart library * ====================================== * * Project Info: http://www.jfree.org/jfreechart/index.html * Project Lead: David Gilbert ([email protected]); * * (C) Copyright 2000-2003, by Simba Management Limited and Contributors. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. * * ------------------------- * VerticalBarChartDemo.java * ------------------------- * (C) Copyright 2002, 2003, by Simba Management Limited and Contributors. * * Original Author: David Gilbert (for Simba Management Limited); * Contributor(s): -; * * $Id: VerticalBarChartDemo.java,v 1.1 2003/04/23 09:58:51 mungady Exp $ * * Changes * ------- * 11-Jun-2002 : Version 1 (DG); * 25-Jun-2002 : Removed redundant imports (DG); * 09-Oct-2002 : Added frame centering (DG); * 18-Nov-2002 : Changed from DefaultCategoryDataset to DefaultTableDataset (DG); * */package org.jfree.chart.demo;import java.awt.Color;import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartPanel; import org.jfree.chart.JFreeChart; import org.jfree.chart.axis.HorizontalCategoryAxis; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.plot.CategoryPlot; import org.jfree.data.DefaultCategoryDataset; import org.jfree.ui.ApplicationFrame; import org.jfree.ui.RefineryUtilities;/** * A simple demonstration application showing how to create a vertical bar chart. * * @author David Gilbert */ public class VerticalBarChartDemo extends ApplicationFrame { /** * Creates a new demo instance. * * @param title the frame title. */ public VerticalBarChartDemo(String title) { super(title); // row keys... String series1 = "First"; String series2 = "Second"; String series3 = "Third"; // column keys... String category1 = "Category 1"; String category2 = "Category 2"; String category3 = "Category 3"; String category4 = "Category 4"; String category5 = "Category 5"; String category6 = "Category 6"; String category7 = "Category 7"; String category8 = "Category 8"; // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, series1, category1); dataset.addValue(4.0, series1, category2); dataset.addValue(3.0, series1, category3); dataset.addValue(5.0, series1, category4); dataset.addValue(5.0, series1, category5); dataset.addValue(7.0, series1, category6); dataset.addValue(7.0, series1, category7); dataset.addValue(8.0, series1, category8); dataset.addValue(5.0, series2, category1); dataset.addValue(7.0, series2, category2); dataset.addValue(6.0, series2, category3); dataset.addValue(8.0, series2, category4); dataset.addValue(4.0, series2, category5); dataset.addValue(4.0, series2, category6); dataset.addValue(2.0, series2, category7); dataset.addValue(1.0, series2, category8); dataset.addValue(4.0, series3, category1); dataset.addValue(3.0, series3, category2); dataset.addValue(2.0, series3, category3); dataset.addValue(3.0, series3, category4); dataset.addValue(6.0, series3, category5); dataset.addValue(3.0, series3, category6); dataset.addValue(4.0, series3, category7); dataset.addValue(3.0, series3, category8); // create the chart... JFreeChart chart = ChartFactory.createVerticalBarChart( "Vertical Bar Chart", // chart title "Category", // domain axis label "Value", // range axis label dataset, // data true, // include legend true, false ); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart... chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation... CategoryPlot plot = chart.getCategoryPlot(); // skip some labels if they overlap... HorizontalCategoryAxis domainAxis = (HorizontalCategoryAxis) plot.getDomainAxis(); domainAxis.setSkipCategoryLabelsToFit(true); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel... ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); } /** * Starting point for the demonstration application. * * @param args ignored. */ public static void main(String[] args) { VerticalBarChartDemo demo = new VerticalBarChartDemo("Vertical Bar Chart Demo"); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); }} 错误提示 cannot access class org.jfree.chart.axis 总之那几个import都出错 我把整个org文件夹都放到我的工程目录里了,也不行
"VerticalBarChartDemo.java": Error #: 302 : cannot access class org.jfree.chart.ChartFactory; java.io.IOException: class not found: class org.jfree.chart.ChartFactory at line 45, column 24 "VerticalBarChartDemo.java": Error #: 302 : cannot access class org.jfree.chart.ChartPanel; java.io.IOException: class not found: class org.jfree.chart.ChartPanel at line 46, column 24
我下的是jfreechart-0.9.8
说could not find the main class,program will exit
你看看verticalbarchartdemo中有main吗?
真不知为什么?
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert ([email protected]);
*
* (C) Copyright 2000-2003, by Simba Management Limited and Contributors.
*
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* -------------------------
* VerticalBarChartDemo.java
* -------------------------
* (C) Copyright 2002, 2003, by Simba Management Limited and Contributors.
*
* Original Author: David Gilbert (for Simba Management Limited);
* Contributor(s): -;
*
* $Id: VerticalBarChartDemo.java,v 1.1 2003/04/23 09:58:51 mungady Exp $
*
* Changes
* -------
* 11-Jun-2002 : Version 1 (DG);
* 25-Jun-2002 : Removed redundant imports (DG);
* 09-Oct-2002 : Added frame centering (DG);
* 18-Nov-2002 : Changed from DefaultCategoryDataset to DefaultTableDataset (DG);
*
*/package org.jfree.chart.demo;import java.awt.Color;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.HorizontalCategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.data.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;/**
* A simple demonstration application showing how to create a vertical bar chart.
*
* @author David Gilbert
*/
public class VerticalBarChartDemo extends ApplicationFrame { /**
* Creates a new demo instance.
*
* @param title the frame title.
*/
public VerticalBarChartDemo(String title) { super(title); // row keys...
String series1 = "First";
String series2 = "Second";
String series3 = "Third"; // column keys...
String category1 = "Category 1";
String category2 = "Category 2";
String category3 = "Category 3";
String category4 = "Category 4";
String category5 = "Category 5";
String category6 = "Category 6";
String category7 = "Category 7";
String category8 = "Category 8"; // create the dataset...
DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, series1, category1);
dataset.addValue(4.0, series1, category2);
dataset.addValue(3.0, series1, category3);
dataset.addValue(5.0, series1, category4);
dataset.addValue(5.0, series1, category5);
dataset.addValue(7.0, series1, category6);
dataset.addValue(7.0, series1, category7);
dataset.addValue(8.0, series1, category8); dataset.addValue(5.0, series2, category1);
dataset.addValue(7.0, series2, category2);
dataset.addValue(6.0, series2, category3);
dataset.addValue(8.0, series2, category4);
dataset.addValue(4.0, series2, category5);
dataset.addValue(4.0, series2, category6);
dataset.addValue(2.0, series2, category7);
dataset.addValue(1.0, series2, category8); dataset.addValue(4.0, series3, category1);
dataset.addValue(3.0, series3, category2);
dataset.addValue(2.0, series3, category3);
dataset.addValue(3.0, series3, category4);
dataset.addValue(6.0, series3, category5);
dataset.addValue(3.0, series3, category6);
dataset.addValue(4.0, series3, category7);
dataset.addValue(3.0, series3, category8); // create the chart...
JFreeChart chart = ChartFactory.createVerticalBarChart(
"Vertical Bar Chart", // chart title
"Category", // domain axis label
"Value", // range axis label
dataset, // data
true, // include legend
true,
false
); // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART... // set the background color for the chart...
chart.setBackgroundPaint(new Color(0xBBBBDD)); // get a reference to the plot for further customisation...
CategoryPlot plot = chart.getCategoryPlot(); // skip some labels if they overlap...
HorizontalCategoryAxis domainAxis = (HorizontalCategoryAxis) plot.getDomainAxis();
domainAxis.setSkipCategoryLabelsToFit(true); // set the range axis to display integers only...
NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // OPTIONAL CUSTOMISATION COMPLETED. // add the chart to a panel...
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel); } /**
* Starting point for the demonstration application.
*
* @param args ignored.
*/
public static void main(String[] args) { VerticalBarChartDemo demo = new VerticalBarChartDemo("Vertical Bar Chart Demo");
demo.pack();
RefineryUtilities.centerFrameOnScreen(demo);
demo.setVisible(true); }}
错误提示
cannot access class org.jfree.chart.axis
总之那几个import都出错
我把整个org文件夹都放到我的工程目录里了,也不行
"VerticalBarChartDemo.java": Error #: 302 : cannot access class org.jfree.chart.ChartPanel; java.io.IOException: class not found: class org.jfree.chart.ChartPanel at line 46, column 24
这个地方可以下载jfreechart-0.9.8.zip
1.tools->configure libraries.
点new...,在name栏写一个有意义的名字.再点add...,增加一个jar,找到你要加的jar文件,ok.
2.在当前工程的properties中,paths->Required Libraries,点add...,选择你给的"有意义的名字",ok.在jbuilder中,你import com.xxx,等时,应能见到你的jar package 信息.
打import org.时后面有提示啊
真不知为什么?
import org.jfree.chart.*;有提示吗?
若有的话,那我就不知道该怎么办了。
若没有的话,那就是上面的配置不正确,别急,多来几次就熟练了。
jfreechart-0.9.8/jfreechart-0.9.8-demo.jar
jfreechart-0.9.8/lib/gnujaxp.jar
jfreechart-0.9.8/lib/jcommon-0.8.0.jar
jfreechart-0.9.8/lib/servlet.jar
全部加入到库中,就OK。