Add values to a specified series in a DynamicTimeSeriesCollection

心不动则不痛 提交于 2019-11-27 09:47:11
trashgod

Assuming you started from here, you've specified a dataset with two series, but you're only appending one value with each tick of the Timer. You need two values for each tick. Here's how I modified the original to get the picture below:

final DynamicTimeSeriesCollection dataset =
    new DynamicTimeSeriesCollection(2, COUNT, new Second());
...
dataset.addSeries(gaussianData(), 0, "Human");
dataset.addSeries(gaussianData(), 1, "Alien");
...
timer = new Timer(FAST, new ActionListener() {

    // two values appended with each tick
    float[] newData = new float[2];

    @Override
    public void actionPerformed(ActionEvent e) {
        newData[0] = randomValue();
        newData[1] = randomValue();
        dataset.advanceTime();
        dataset.appendData(newData);
    }
});

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!