JavaFX LineChart - 绘制数组 [英] JavaFX LineChart - draw array

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

问题描述

我正在尝试在JavaFX中使用 LineChart 向用户显示数据。我有一个Float数组(不是原语,对象,如 Float [] ),可以添加,可以是512到4096点长。

I'm trying to display data to a user with a LineChart in JavaFX. I have an array of Float (not the primitive, the object, as in Float[]) that is ready to be added that could be anywhere from 512 to 4096 points long.

LineChart 的所有示例和帮助都表明必须使用<$ c $逐点添加数据c> XYChart.Series.getData()。add(new XYChart.Data(X,Y))其中X是索引,Y是Float [index]的值。这真的非常慢,因为这种方法需要循环遍历数组,但它确实有效。我希望 LineChart 以30FPS更新,但现在小于1FPS:/

All the examples and help for LineChart show that data has to be added point by point using XYChart.Series.getData().add(new XYChart.Data(X, Y)) where X would be the index and Y would be the value at Float[index]. This is really, really slow since this approach requires looping through the array, but it works. I'd like the LineChart to update at 30FPS but it as less than 1FPS right now :/

是否有一个更快的方法,我可以在JavaFX LineChart 类中抛出一个数组并让它绘制而不循环并添加每个点?

Is there a faster way where I can just toss an array at the JavaFX LineChart class and have it draw without looping through and adding each point?

编辑(找到解决方案)

srm,这个概念有效!

srm, that concept works!

在第一次运行时,只需用新的XYChart.Data(X,Y)填充 XYChart.Series 。然后使用 XYChart.Series.get(index).setYData(NewValue)

On the first run, just fill the XYChart.Series with new XYChart.Data(X,Y). Then loop through and fetch and update using XYChart.Series.get(index).setYData(NewValue)

推荐答案

好的,不得不删除我之前的帖子,因为无法阅读。

Ok, had to delete my previous post for not being able to read.

您是否尝试过使用XYChartBuilder?看起来您可以使用在运行时期间可能更改的数据点的初始列表
数据(ObservableList> x)
我没有使用过我的第一个插图,即您只创建一个列表这个,然后只改变你需要的数据点(虽然我可能在这里完全错误)。试试看,我很想听到这个消息!

Have you tried using the XYChartBuilder? It looks like you can use an initial list of datapoints that might be changed during runtime data(ObservableList> x) I haven't worked with that that my first inutition is, that you create only one list of this and then change only the datapoints you need (while I may be completely wrong here). Try it and see, I'm keen to hear back on this!

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

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