如何更新JavaFX LineChart数据 [英] How to update JavaFX LineChart data

查看:76
本文介绍了如何更新JavaFX LineChart数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JavaFX LineChart来显示服务器性能,我希望通过从服务器获取的数据来动态更新图形.

I using a JavaFX LineChart to display server performance, i want the graph to be updated dynamically with the data fetch from the servers.

我如何在一个图形中添加新数据并在图形中始终保持相同的时间范围(在我的情况下,时间是X轴),Y轴是每秒的请求数.

How can i add new data one the graph and keep always the same time range in graph (in my case the time is X axis), and Y axis is number of request per second.

我正在使用最新的JavaFX JDK7u6

edit: I using latest JavaFX JDK7u6

推荐答案

获取系列:

XYChart.Series<Number, Number> s = lineChart.getData().get(0);

通过删除第一个元素并添加新元素来移动时间范围/范围:

Shift the time frame/range by removing first element and adding new one:

s.getData().remove(0);
s.getData().add(new LineChart.Data<Number,Number>(time_from_server, data_from_server));

这篇关于如何更新JavaFX LineChart数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆