【发布时间】:2017-06-16 01:38:04
【问题描述】:
Raspian - Raspberry Pi 上的 LineChart 的响应速度比正常速度慢。我正在编写示波器并不断重绘 2 个系列,每组 500 个点(总共 1000 个点)。动画已关闭。数据收集是高性能的(低于 2 毫秒)。当前数据重绘时间为800 ms左右。所需的重绘时间至少为 100 毫秒。我在下面包含了代码 sn-ps。在树莓派上显示高性能 javafx 图表的最佳实践是什么?我采取了错误的方法吗?我应该使用不同类型的图表来连续重绘两条线吗?
平台:
- 树莓派 v. 3
- 操作系统:Raspian 版本 8 (jessie)
- Java 版本:
- java版本“1.8.0_65”
- Java(TM) SE 运行时环境(内部版本 1.8.0_65-b17)
- Java HotSpot(TM) 客户端虚拟机(内部版本 25.65-b01,混合模式)
- JavaFX 版本:armv6hf-sdk 8.0.102(构建 b00)
- 内存分割:512 MB 图形,512 MB 系统
- 视频:HDMI
- SoC:博通 BCM2837
- CPU:4×ARM Cortex-A53,1.2GHz
显示代码
@FXML
LineChart oscilloscope;
//indicates that the previous data has been displayed
//and that the latest data should now be displayed
//didn't bother to synchronize
boolean needsUpdating = true;
protected void startDisplay() {
oscilloscope.setAnimated(false);
oscilloscope.setCreateSymbols(false);
oscilloscope.getXAxis().setLabel("Time (ms)");
oscilloscope.getXAxis().setAutoRanging(false);
oscilloscope.getYAxis().setLabel("Volts (v)");
oscilloscope.getYAxis().setAutoRanging(false);
new Thread() {
public void run() {
while (!done) {
XYChart.Series ch1 = getChan1Data();
XYChart.Series ch2 = getChan2Data();
ch1.setName("Channel 1");
ch2.setName("Channel 2");
if (needsUpdated) {
needsUpdated = false;
Platform.runLater(new Runnable() {
@Override
public void run() {
//performance is the same whether I use this or
//oscilloscope.getData().clear()
oscilloscope.setData(FXCollections.observableArrayList());
oscilloscope.getData().addAll(ch1, ch2);
needsUpdating = true;
} //end run()
} //end Platform.runLater()
} //end if(needsUpdating)
} //end while(!done)
}.start(); //end new Thread
} //end startDisplay()
【问题讨论】:
-
注意:与这里的 ItachiUchiha 答案不同:stackoverflow.com/questions/22089022/line-chart-live-update,我们需要在每次迭代中替换所有数据,而不是追加数据。
-
在这里查看了 Jewelsea 的通用 javafx 解决方案:gist.github.com/jewelsea
-
更新:尝试使用带有 FX 集成的 JFreeChart LineChart。这看起来更慢。
标签: java linux javafx raspberry-pi linechart