JSON.js
var Jsondata = {
"label1": 0,
"label2": 0,
"label3": 2,
"label4": 0,
"label5": 0
}
var labels = //?? have to get the labels from the Jsondata
var data = //?? have to get the numbers from the Jsondata
我正在使用它来制作使用chartjs的折线图,代码如下。
type: 'line',
data: {
labels: labels //["label1","label2","label3","label4", "label5""],
datasets: [{
label:'',
fill: 'false',
data: data //[0, 3, 6, 4, 5,3,2],
答案 0 :(得分:1)
您可以使用内置的Object
助手keys()
和values()
:
var Jsondata = {
"label1": 0,
"label2": 0,
"label3": 2,
"label4": 0,
"label5": 0
}
var labels = Object.keys(Jsondata)
var data = Object.values(Jsondata)
标签:
["label1", "label2", "label3", "label4", "label5"]
数据:
[0, 0, 2, 0, 0]