2012-04-03 5 views
2

から私はTimeSeriesCollectionチャートに動的なデータをrondom置くこのexempleウィッヒで働いています。セーブ/ロードはJFreeChart TimeSeriesCollectionチャートはXML

the data when first running the application

after a while i can not have the old data like those of the first picture

私の問題は、私はどのように見つけることができないということである:彼らは渡すとき

1-(最後の時間の)古いデータのトラックを作成します水平スクロールバーを実装するだけで、ビュー領域の左境界線(データポイントが右から左に移動するため)

2私はいつでも自分のデータを保存するのに良い選択ですかすべてデータの履歴ですか?

public class DynamicDataDemo extends ApplicationFrame { 
    /** The time series data. */ 
    private TimeSeries series; 

    /** The most recent value added. */ 
    private double lastValue = 100.0; 


public DynamicDataDemo(final String title) { 

    super(title); 
    this.series = new TimeSeries("Random Data", Millisecond.class); 
    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series); 
    final JFreeChart chart = createChart(dataset); 

    final ChartPanel chartPanel = new ChartPanel(chart); 

    final JPanel content = new JPanel(new BorderLayout()); 
    content.add(chartPanel); 
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); 
    setContentPane(content); 

} 


private JFreeChart createChart(final XYDataset dataset) { 
    final JFreeChart result = ChartFactory.createTimeSeriesChart(
     "Dynamic Data Demo", 
     "Time", 
     "Value", 
     dataset, 
     true, 
     true, 
     false 
    ); 
    final XYPlot plot = result.getXYPlot(); 
    ValueAxis axis = plot.getDomainAxis(); 
    axis.setAutoRange(true); 
    axis.setFixedAutoRange(60000.0); // 60 seconds 
    axis = plot.getRangeAxis(); 
    axis.setRange(0.0, 200.0); 
    return result; 
} 


public void go() { 

     final double factor = 0.90 + 0.2 * Math.random(); 
     this.lastValue = this.lastValue * factor; 
     final Millisecond now = new Millisecond(); 
     System.out.println("Now = " + now.toString()); 
     this.series.add(new Millisecond(), this.lastValue); 

} 


public static void main(final String[] args) throws InterruptedException { 

    final DynamicDataDemo demo = new DynamicDataDemo("Dynamic Data Demo"); 
    demo.pack(); 
    RefineryUtilities.centerFrameOnScreen(demo); 
    demo.setVisible(true); 

    while(true){ 

     demo.go(); 
     Thread.currentThread().sleep(1000); 
    } 

} 



} 

答えて

2
  1. exampleは最大項目の年齢とカウントにTimeSeriesで指定default valuesを使用しています。要件に合わせて変更する必要があります。

  2. XMLは問題ありませんが、高率ではボリュームがあります。それに従って計画する。

イベントディスパッチスレッドをブロック避けるためにjavax.swing.Timerを使用することも、このexampleを参照してください。

+0

どうもありがとう、私は持っていたいものを正確ではありません最初の部分のHEMMため、TimeSeries.setMaximumItemAge(長い)をチェックすることによって、私はそれが表示領域に古いデータを保持し、代わりに追加するグラフを圧縮することがわかりました水平スクロールバー私は彼がしていたようにグラフを保持し、同じ時間に古いデータを追跡したいからです。 –

+0

さらにモデルとビューを分離する必要があります。ページング手法が提案されています[ここ](http://stackoverflow.com/a/6849654/230513)。 – trashgod