Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Js function running so slow in qml6
Forum Updated to NodeBB v4.3 + New Features

Js function running so slow in qml6

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 998 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Aminsl
    wrote on 21 Jan 2024, 06:37 last edited by
    #1

    I'm currently working on a line chart and trying to generate a random series of points for it. I wrote some js codes in order to generate a random series for my line chart but when I want to generate 17000 points or even more , my code runs so slow and it takes about 1 minute to generate the series for my line chart. I don't know if I'm writing inefficiently in js or should I write it in a separate thread ?

    ChartView {
                    id: centralLineChartView
                    legend.visible: false
                    antialiasing: true
                    anchors.fill: parent
                    axes: [
                        ValuesAxis {
                            id: xAxis
                            min: 0
                            max: 1000
                        } ,
                        ValuesAxis {
                            id: yAxis
                            min: -130
                            max: 10
                        }
                    ]
    
     Component.onCompleted: {
         var series = centralLineChartView.createSeries(ChartView.SeriesTypeLine , "Series" , xAxis , yAxis);
          series.color = Qt.rgba(Math.random() , Math.random() , Math.random() , 1);
           series.hovered.connect(function(point, state{console.log(point);});
    
       for(var i = 0; i <= 1000; i ++){
         var y = Math.random() * (-120 - (-95)) +(-95);
         series.append(i , y);
    
                        }
                    }
                }
    

    Please let me know if I have to provide more code .

    J 1 Reply Last reply 21 Jan 2024, 15:31
    0
    • A Aminsl
      21 Jan 2024, 06:37

      I'm currently working on a line chart and trying to generate a random series of points for it. I wrote some js codes in order to generate a random series for my line chart but when I want to generate 17000 points or even more , my code runs so slow and it takes about 1 minute to generate the series for my line chart. I don't know if I'm writing inefficiently in js or should I write it in a separate thread ?

      ChartView {
                      id: centralLineChartView
                      legend.visible: false
                      antialiasing: true
                      anchors.fill: parent
                      axes: [
                          ValuesAxis {
                              id: xAxis
                              min: 0
                              max: 1000
                          } ,
                          ValuesAxis {
                              id: yAxis
                              min: -130
                              max: 10
                          }
                      ]
      
       Component.onCompleted: {
           var series = centralLineChartView.createSeries(ChartView.SeriesTypeLine , "Series" , xAxis , yAxis);
            series.color = Qt.rgba(Math.random() , Math.random() , Math.random() , 1);
             series.hovered.connect(function(point, state{console.log(point);});
      
         for(var i = 0; i <= 1000; i ++){
           var y = Math.random() * (-120 - (-95)) +(-95);
           series.append(i , y);
      
                          }
                      }
                  }
      

      Please let me know if I have to provide more code .

      J Offline
      J Offline
      JonB
      wrote on 21 Jan 2024, 15:31 last edited by JonB
      #2

      @Aminsl
      It is slow because you are doing many individual append()s, and Qt Charts is poor at that, speed-wise. Read the discussion in https://forum.qt.io/topic/140576/qt-charts-extremely-slow-qlineseries. Backed up by https://forum.qt.io/topic/145620/chartview-is-too-slow and others. Consider the workaround there: build the points into a JS list and use replace().

      A 1 Reply Last reply 22 Jan 2024, 07:57
      0
      • J JonB
        21 Jan 2024, 15:31

        @Aminsl
        It is slow because you are doing many individual append()s, and Qt Charts is poor at that, speed-wise. Read the discussion in https://forum.qt.io/topic/140576/qt-charts-extremely-slow-qlineseries. Backed up by https://forum.qt.io/topic/145620/chartview-is-too-slow and others. Consider the workaround there: build the points into a JS list and use replace().

        A Offline
        A Offline
        Aminsl
        wrote on 22 Jan 2024, 07:57 last edited by
        #3

        @JonB I just did but it didn't work properly and no series has drawn into the chart. Did I do anything wrong ? According to the document , this replace() function only accepts numerical values not a whole list , right ?

        Component.onCompleted: {
                var series = centralLineChartView.createSeries(ChartView.SeriesTypeLine , "Series" , xAxis , yAxis);
                 series.color = Qt.rgba(Math.random() , Math.random() , Math.random() , 1);
                 series.hovered.connect(function(point, state) {console.log(point);});
        
                            var pointsList = [];
        
                            for(var i = 0; i <= 17000; i ++){
                                var y = Math.random() * (-120 - (-95)) +(-95);
                                pointsList[i] = Qt.point(i,y);
                            }
        
                            series.replace(pointsList);
        
                        }
        
        P J 2 Replies Last reply 22 Jan 2024, 13:10
        0
        • A Aminsl
          22 Jan 2024, 07:57

          @JonB I just did but it didn't work properly and no series has drawn into the chart. Did I do anything wrong ? According to the document , this replace() function only accepts numerical values not a whole list , right ?

          Component.onCompleted: {
                  var series = centralLineChartView.createSeries(ChartView.SeriesTypeLine , "Series" , xAxis , yAxis);
                   series.color = Qt.rgba(Math.random() , Math.random() , Math.random() , 1);
                   series.hovered.connect(function(point, state) {console.log(point);});
          
                              var pointsList = [];
          
                              for(var i = 0; i <= 17000; i ++){
                                  var y = Math.random() * (-120 - (-95)) +(-95);
                                  pointsList[i] = Qt.point(i,y);
                              }
          
                              series.replace(pointsList);
          
                          }
          
          P Do not disturb
          P Do not disturb
          piervalli
          wrote on 22 Jan 2024, 13:10 last edited by
          #4

          @Aminsl

          If you call "series.append(i , y)" I think that you call the paint event for each append.

          try with
          var pointsList = new Array(17000), it creates an array wih 17000 empty records ,assign points, than you should creates ChartView with already array.
          I neve tested but should be a good point.

          A 1 Reply Last reply 23 Jan 2024, 07:16
          0
          • A Aminsl
            22 Jan 2024, 07:57

            @JonB I just did but it didn't work properly and no series has drawn into the chart. Did I do anything wrong ? According to the document , this replace() function only accepts numerical values not a whole list , right ?

            Component.onCompleted: {
                    var series = centralLineChartView.createSeries(ChartView.SeriesTypeLine , "Series" , xAxis , yAxis);
                     series.color = Qt.rgba(Math.random() , Math.random() , Math.random() , 1);
                     series.hovered.connect(function(point, state) {console.log(point);});
            
                                var pointsList = [];
            
                                for(var i = 0; i <= 17000; i ++){
                                    var y = Math.random() * (-120 - (-95)) +(-95);
                                    pointsList[i] = Qt.point(i,y);
                                }
            
                                series.replace(pointsList);
            
                            }
            
            J Offline
            J Offline
            JonB
            wrote on 22 Jan 2024, 15:14 last edited by
            #5

            @Aminsl

            this replace() function only accepts numerical values not a whole list , right ?

            Sorry, I don't know what this means.
            Your code looks reasonable to me. I don't use QML. From my recollection of JS it is OK to just extend an array by assigning to higher indexes. But the example I pointed to showed

            for i in self.x:
                 points.append(QPointF(i, self.y[i]))   # filling points with my prepared data 
            serie1.replace(points)  # fill list of points in one call
            

            so I don't know why you didn't just use that. Or pre-allocate per @piervalli 's suggestion. Per the references others have found this works for them, and reduces the time dramatically, that's all I know.

            1 Reply Last reply
            0
            • P piervalli
              22 Jan 2024, 13:10

              @Aminsl

              If you call "series.append(i , y)" I think that you call the paint event for each append.

              try with
              var pointsList = new Array(17000), it creates an array wih 17000 empty records ,assign points, than you should creates ChartView with already array.
              I neve tested but should be a good point.

              A Offline
              A Offline
              Aminsl
              wrote on 23 Jan 2024, 07:16 last edited by
              #6

              @piervalli you mean I create the series in another class and pass it back to my chart view ?

              P 1 Reply Last reply 24 Jan 2024, 11:55
              0
              • A Aminsl
                23 Jan 2024, 07:16

                @piervalli you mean I create the series in another class and pass it back to my chart view ?

                P Do not disturb
                P Do not disturb
                piervalli
                wrote on 24 Jan 2024, 11:55 last edited by
                #7

                @Aminsl
                Yes,

                1 Reply Last reply
                0

                6/7

                23 Jan 2024, 07:16

                • Login

                • Login or register to search.
                6 out of 7
                • First post
                  6/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved