[Solved]How to push data to inside element of a variable in QML?
-
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.
-
@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.
SoChartLineData["labels"]
will give you thelabels
value viz. an array. In the similar way you can accessdatasets
.
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 upChartLineData["datasets"][0]["data"].push(500) //access data and push a new value console.log(ChartLineData["datasets"][0]["data"]) //check the new array