你下的jfreechart是那个版本
在0.98以后包由com.jrefinery.*改变为:org.jfree
比如0.98以前用
import com.jrefinery.data.Day;
以后用
import org.jfree.data.Day;
在0.98以后包由com.jrefinery.*改变为:org.jfree
比如0.98以前用
import com.jrefinery.data.Day;
以后用
import org.jfree.data.Day;
import org.jfree.data.Day;
import org.jfree.chart.TimeSeries;
import org.jfree.chart.TimeSeriesCollection;
import org.jfree.chart.TimeSeriesDataPair;
改成:
import com.jrefinery.data.Day;
import com.jrefinery.chart.TimeSeries;
import com.jrefinery.chart.TimeSeriesCollection;
import com.jrefinery.chart.TimeSeriesDataPair;
看可以找到吗
import org.jfree.data.TimeSeries;
import org.jfree.data.TimeSeriesCollection;这三个找到了,放到了data\time目录了import org.jfree.data.TimeSeriesDataPair;没有,我搜了
http://www-900.ibm.com/developerWorks/cn/java/l-jfreechart/
这个地址的,运行后没能生成图片???我用的是这个
package testchart;import java.awt.Color;
import java.awt.GradientPaint;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import org.jfree.data.*;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import java.io.File;
//import com.jrefinery.chart.*;
//import com.jrefinery.data.*;
/**
* <p>走势图生成程序 </p>
* <p>Description:本走势图生成程序可以生成二维坐标的走势曲线图 </p>
* @author 于秉超
* @version 1.0
*/
public class CreatPriceChart { public CreatPriceChart(double[][] XYData,int width,int height,String filename) {
this.setXYData(XYData);
this.setWidth(width);
this.setHeight(height);
this.setFilename(filename);
}
/**
* 将走势图保存为JPG文件
* @throws IOException
*/
public void saveChart()throws IOException{
File file = new File(filename) ;
//将走势图保存为文件
ChartUtilities.saveChartAsJPEG(file, createChart(), width, height);
}
/**
* 将XYData数组的数据转换为程序识别的坐标数据
* @return
* @throws SQLException
* @throws Exception
*/
public XYSeriesCollection createXYSeriesCollection()
throws java.sql.SQLException ,Exception{
//声明坐标搜集类
XYSeriesCollection collection = new XYSeriesCollection();
//声明保存坐标类
XYSeries t1 = new XYSeries("");
try {
//将坐标添加到类中
for(int j=0;j<XYData[0].length;j++){
t1.add(XYData[0][j],XYData[1][j]);
}
}catch (Exception e) {
System.err.println(e.getMessage());
}
//将数据搜集起来
collection.addSeries(t1);
return collection;
}
/**
* 根据坐标数据生成走势图曲线
* @return
*/
public JFreeChart createChart() {
JFreeChart chart;//定义一个图表
try {
//将图表转换为可用的数据
XYDataset xyData1 = createXYSeriesCollection();
//生成图表,createXYChart的参数大家可以更改一下看看效果
chart = ChartFactory.createLineXYChart(
"图表标题", // 图表标题
"横坐标", // 目录轴的显示标签
"纵坐标", // 数值轴的显示标签
xyData1, // 数据集
PlotOrientation.VERTICAL, // 图表方向:水平、垂直
false, // 是否显示图例(对于简单的柱状图必须是false)
true, // 是否生成工具
false // 是否生成URL链接
);
//定义图表背景图案
chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 1200, 0, Color.yellow));
return chart;
}catch (Exception e) {
return null;
}
}
public void setXYData(double[][] XYData) {
this.XYData = XYData;
}
public double[][] getXYData(){
return XYData;
}
public void setWidth(int width) {
this.width = width;
}
public int getWidth() {
return width;
}
public void setHeight(int height) {
this.height = height;
}
public int getHeight() {
return height;
}
public void setFilename(String filename) {
this.filename = filename;
}
public String getFilename() {
return filename;
} private double[][] XYData;//走势图所需的X轴和Y轴的数据
private int width;//走势图宽度
private int height;//走势图高度
private String filename;//保存的文件名,含全路径
}
------------package testchart;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import testchart.CreatPriceChart;public class Frame1 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout(); //Construct the frame
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
testCreatXYChart();//调用生成图表类
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
//setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
}
//关窗口事件
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main(String[] args) {
new Frame1().show();
}
//测试图表生成类
void testCreatXYChart(){
//XY轴坐标值
double XYData[][]={{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30},
{800,810,780,740,745,750,720,730,700,750,700,780,800,780,787,750,768,803,847,859,788,780,820,855,796,797,768,817,829}
};
CreatPriceChart cpc=new CreatPriceChart(XYData,680,300,"c:\\try.jpg");
try{
cpc.saveChart();
}catch(Exception e){
System.out.println(e);
}
}
//显示生成的图表
public void paint(Graphics g){
Image img=Toolkit.getDefaultToolkit().getImage("c:\\try.jpg");
g.drawImage(img,10,10,img.getWidth(this),img.getHeight(this),Color.red,this);
}
//消除闪烁
public void update(Graphics g){
paint(g);
}
}
这是折线图,我要曲线
http://www.cn-java.com/target/news.php?news_id=2512
http://www.cn-java.com/search_result.php?record_first=0
找不到TimeSeriesDataPair.java这个文件?