gpt4 book ai didi

java - 从 XML 保存/加载 jFreechart TimeSeriesCollection 图表

转载 作者:行者123 更新时间:2023-11-30 09:38:43 25 4
gpt4 key购买 nike

我正在使用这个 exemple将随机动态数据放入 TimeSeriesCollection 图表。

the data when first running the application

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

我的问题是我找不到如何:

1- 当旧数据(最后一小时)通过 View 区域的左边界(因为数据点从右向左移动)时,只需通过实现水平滚动条。

2- 当我想要所有数据的历史记录时,XML 是保存数据的好选择吗?

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);
}

}



}

最佳答案

  1. example使用 default valuesTimeSeries 中指定最大项目年龄和数量。您需要更改它们以满足您的要求。

  2. XML 很好,但对于高费率来说它太庞大了;相应地计划。

另见 example它使用 javax.swing.Timer 来避免阻塞事件调度线程。

关于java - 从 XML 保存/加载 jFreechart TimeSeriesCollection 图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10002910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com