I have 2 var below to update datasets and labels of my chart.
function updateChart(){
var newdatasets= "[10, 20, 30, 40]";
var newlabels= "['label1', 'label2', 'label3', 'label4']";
myChart.data.datasets[0].data = JSON.parse(newdatasets); //this work
myChart.data.labels = JSON.parse(newlabels); //this does not work
}
Why JSON.parse work with newdatasets
but wont work with newlabels
? The JSON.parse(newdatasets)
updated the chart datasets successfully but JSON.parse(newlabels)
fail to update chart labels. What can I do to fix this?
Dont ask me to change the var value to ['label1', 'label2', 'label3', 'label4']
without the "
. I know this will work but I want the chart to change from that kind of var value.
Thank you for any help..