折线图 JavaFX 性能 [英] LineChart JavaFX Performance

查看:40
本文介绍了折线图 JavaFX 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Raspian - Raspberry Pi 上遇到 LineChart 比正常响应慢.我正在编写示波器并不断重绘 2 个系列的 500 个点(总共 1000 个点).动画已关闭.数据收集是高性能的(低于 2 毫秒).当前数据重绘时间为 800 毫秒左右.所需的重绘时间至少为 100 毫秒.我在下面包含了代码片段.在树莓派上显示高性能 javafx 图表的最佳实践是什么?我采取了错误的方法吗?我应该使用不同类型的图表来连续重绘两条线吗?

I'm experiencing slower than normal response for a LineChart on Raspian - Raspberry Pi. I'm coding an oscilloscope and continuously redrawing 2 series of 500 points (total of 1000 points). Animation is off. Data collection is performant (under 2ms). Current data redraw time is 800 ms or so. Desired redraw time is at least 100ms. I've included code snippets below. What is the best practice for performant javafx chart display on a raspberry pi? Am I taking the wrong approach? Should I be using a different kind of chart for continuously redrawing two lines?

平台:

  • 树莓派 v. 3
    • 操作系统:Raspian 版本 8 (jessie)
    • Java 版本:
      • java 版本1.8.0_65"
      • Java(TM) SE 运行时环境(版本 1.8.0_65-b17)
      • Java HotSpot(TM) 客户端 VM(构建 25.65-b01,混合模式)

      显示代码

      @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()
      

      推荐答案

      我发现从图表中删除网格线有很大帮助.

      I found that removing gridlines from the charts helps immensely.

      例如

      chart.setHorizontalGridLinesVisible(false);
      chart.setVerticalGridLinesVisible(false);
      

      没有尝试减少网格线的数量.

      Haven't tried to reduce the number of grid lines.

      这篇关于折线图 JavaFX 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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