我正在处理一个浮点图,我无法将 json 字符串转换为所需的浮点图格式。以下是我尝试过的。
我的杰森
Data: [
{ "Day": 8, "Visits": 145 },
{ "Day": 7, "Visits": 26 }
];
我试图实现的格式:[[0, 12], [1, 2], [2, 2], [3, 3], [4, 4]];
$(document).ready(function () {
var data = [{ "Day": 8, "Visits": 145 }, { "Day": 7, "Visits": 26 }];
var dailyHits = [];
$.each(data, function (_index, _item) {
var c = [_item["Day"], _item["Visits"]];
dailyHits.push(c);
});
//var dailyHits1= [[0, 12], [1, 2], [2, 2], [3, 3], [4, 4]];
var chartData = [dailyHits];
console.log(chartData);
$.plot($("#chartHits"), chartData);
});
任何帮助将不胜感激。