LineChart JavaFX Performance

大兔子大兔子 提交于 2019-12-08 02:47:57

问题


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?

Platform:

  • Raspberry Pi v. 3
    • OS: Raspian release 8 (jessie)
    • Java Version:
      • java version "1.8.0_65"
      • Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
      • Java HotSpot(TM) Client VM (build 25.65-b01, mixed mode)
    • JavaFX Version: armv6hf-sdk 8.0.102 (build b00)
    • Memory Split: 512 MB Graphics, 512 MB System
    • Video: HDMI
    • SoC: Broadcom BCM2837
    • CPU: 4× ARM Cortex-A53, 1.2GHz

Display Code

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

回答1:


I found that removing gridlines from the charts helps immensely.

e.g.

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

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



来源:https://stackoverflow.com/questions/41943662/linechart-javafx-performance

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