Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved]How to push data to inside element of a variable in QML?
Forum Updated to NodeBB v4.3 + New Features

[Solved]How to push data to inside element of a variable in QML?

Scheduled Pinned Locked Moved QML and Qt Quick
qmldatapush
3 Posts 2 Posters 1.2k Views 2 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.
  • vishnuV Offline
    vishnuV Offline
    vishnu
    wrote on last edited by vishnu
    #1

    I would like to push data to the inside element **data **of datasets of ChartLineData.Can any one please tell me how to do that?

    var ChartLineData = {
          labels: ["January","February","March","April","May","June","July"],
        datasets: [{
            fillColor : "rgba(220,220,220,0.2)",
            strokeColor : "rgba(220,220,220,1)",
            pointColor : "rgba(220,220,220,1)",
            pointStrokeColor : "#fff",
            pointHighlightFill : "#fff",
            pointHighlightStroke : "rgba(220,220,220,1)",
            **data **: [20,20,40,50,4,35,100,200]
        }]
    }
    

    I am able to push data to labels.
    chartLineData.labels.push("december")
    but
    chartLineData.datasets.data.push(100);// It says cannot call method push of undefined.

    p3c0P 1 Reply Last reply
    0
    • vishnuV vishnu

      I would like to push data to the inside element **data **of datasets of ChartLineData.Can any one please tell me how to do that?

      var ChartLineData = {
            labels: ["January","February","March","April","May","June","July"],
          datasets: [{
              fillColor : "rgba(220,220,220,0.2)",
              strokeColor : "rgba(220,220,220,1)",
              pointColor : "rgba(220,220,220,1)",
              pointStrokeColor : "#fff",
              pointHighlightFill : "#fff",
              pointHighlightStroke : "rgba(220,220,220,1)",
              **data **: [20,20,40,50,4,35,100,200]
          }]
      }
      

      I am able to push data to labels.
      chartLineData.labels.push("december")
      but
      chartLineData.datasets.data.push(100);// It says cannot call method push of undefined.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      @vishnu Well as ChartLineData is an object one way to access the key-value pairs is using [] where you can pass the key to access its value.
      So ChartLineData["labels"] will give you the labels value viz. an array. In the similar way you can access datasets.
      It contains an array of objects and arrays individual values can be accessed by index. But that value itself in an object. And we know its values can be accessed using key. So to sum up

      ChartLineData["datasets"][0]["data"].push(500) //access data and push a new value
      console.log(ChartLineData["datasets"][0]["data"]) //check the new array
      

      157

      vishnuV 1 Reply Last reply
      1
      • p3c0P p3c0

        @vishnu Well as ChartLineData is an object one way to access the key-value pairs is using [] where you can pass the key to access its value.
        So ChartLineData["labels"] will give you the labels value viz. an array. In the similar way you can access datasets.
        It contains an array of objects and arrays individual values can be accessed by index. But that value itself in an object. And we know its values can be accessed using key. So to sum up

        ChartLineData["datasets"][0]["data"].push(500) //access data and push a new value
        console.log(ChartLineData["datasets"][0]["data"]) //check the new array
        
        vishnuV Offline
        vishnuV Offline
        vishnu
        wrote on last edited by
        #3

        @p3c0
        perfect explanation.Thanks a lot

        1 Reply Last reply
        0

        • Login

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