我想在chartJS中使用json。在第一个例子中,我使用了
[ “0”, “76”, “32”, “88”]
一切看起来都很棒。
当我想将JSON数据用作:
时,问题出现在第二个示例中var json = [{“wartosc”:“0”},{“wartosc”:“76”},{“wartosc”:“32”},{“wartosc”:“88”}];
在变量chartjsData中,我希望数据为[“0”,“76”,“32”,“88”],但它不起作用。
var json =[{"wartosc":"0"},{"wartosc":"76"},{"wartosc":"32"},{"wartosc":"88"}];
var chartjsData = [];
for (var i = 0; i < json.lenght; i++) {
chartjsData.push (json[i].wartosc);
}
var areaChartData = {
labels: ["j","j","j","j"],
datasets: [
{
label: "Electronics",
fillColor: "rgba(210, 214, 222, 1)",
strokeColor: "rgba(210, 214, 222, 1)",
pointColor: "rgba(210, 214, 222, 1)",
pointStrokeColor: "#c1c7d1",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: ["0","76","32","88"]
},
{
label: "Digital Goods",
fillColor: "rgba(60,141,188,0.9)",
strokeColor: "rgba(60,141,188,0.8)",
pointColor: "#3b8bba",
pointStrokeColor: "rgba(60,141,188,1)",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(60,141,188,1)",
data: chartjsData
}
]
};
答案 0 :(得分:1)
你拼错了.length
for (var i = 0; i < json.length; i++) {
chartjsData.push (json[i].wartosc);
}