资源简介

JFreeChart实时折线图 利用Jfreechart实现applet的动态折线图 实时显示随机数

资源截图

代码片段和文件信息

package com.cityinforport.demo;
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Jframe;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Millisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
   
public class RealTimeChart extends ChartPanel implements Runnable   
{   
    private static TimeSeries timeSeries;   
    private long value=0;   
       
    public RealTimeChart(String chartContentString titleString yaxisName)   
    {   
        super(createChart(chartContenttitleyaxisName));   
    }   
       
    private static JFreeChart createChart(String chartContentString titleString yaxisName){   
        //创建时序图对象   
        timeSeries = new TimeSeries(chartContentMillisecond.class);   
        TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(timeSeries);   
        JFreeChart jfreechart = ChartFactory.createTimeSeriesChart(title“time(minutes)“yaxisNametimeseriescollectiontruetruefalse);   
        XYPlot xyplot = jfreechart.getXYPlot();   
        //纵坐标设定   
        ValueAxis valueaxis = xyplot.getDomainAxis();   
        //自动设置数据轴数据范围   
        valueaxis.setAutoRange(true);   
        //数据轴固定数据范围 30s   
        valueaxis.setFixedAutoRange(30000D);   
   
        valueaxis = xyplot.getRangeAxis();   
        //valueaxis.setRange(0.0D200D);   
   
        return jfreechart;   
      }   
   
    public void run()   
    {   
        while(true)   
        {   
        try   
        {   
            timeSeries.add(new Millisecond() randomNum());   
            Thread.sleep(300);   
        }   
        catch (InterruptedException e)  {   }   
        }          
    }   
       
    private long randomNum()   
    {      
//        System.out.println((Math.random()*20+80));         
        return (long)(Math.random()*20+80);   
    }  
    
    public static void main(String[] args) {
  
       Jframe frame=new Jframe(“Test Chart“);   
         RealTimeChart rtcp=new RealTimeChart(“Random Data““Random““value“);   
         frame.getContentPane().add(rtcpnew BorderLayout().CENTER);   
         frame.pack();   
         frame.setVisible(true);   
         (new Thread(rtcp)).start();   
         frame.addWindowListener(new WindowAdapter()    
         {   
             public void windowClosing(WindowEvent windowevent)   
             {   
                 System.exit(0);   
             }   
        
         }); 
 }

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件         684  2011-05-28 06:19  jfree\bin\com\cityinforport\demo\RealTimeChart$1.class
     文件        3199  2011-05-28 06:19  jfree\bin\com\cityinforport\demo\RealTimeChart.class
     文件        2794  2011-05-28 06:19  jfree\src\com\cityinforport\demo\RealTimeChart.java
     文件         629  2011-05-28 06:14  jfree\.settings\org.eclipse.jdt.core.prefs
     文件         418  2011-05-28 06:15  jfree\.classpath
     文件         381  2011-05-28 06:14  jfree\.project
     目录           0  2011-05-28 11:01  jfree\bin\com\cityinforport\demo\
     目录           0  2011-05-28 11:01  jfree\src\com\cityinforport\demo\
     目录           0  2011-05-28 11:01  jfree\bin\com\cityinforport\
     目录           0  2011-05-28 11:01  jfree\src\com\cityinforport\
     目录           0  2011-05-28 11:01  jfree\bin\com\
     目录           0  2011-05-28 11:01  jfree\src\com\
     目录           0  2011-05-28 11:01  jfree\.settings\
     目录           0  2011-05-28 11:01  jfree\bin\
     目录           0  2011-05-28 11:01  jfree\src\
     目录           0  2011-05-28 11:01  jfree\

评论

共有 条评论