以http://www.flotcharts.org/flot/examples/stacking/为例,我试图实现相同的,但x轴是time。
https://jsfiddle.net/shorif2000/u6kvfjzc/
processData(json.rows.incidents.data, json.rows.incidents.tab);
function processData(rows, tab) {
p_start = new Date().getTime();
console.log("start process: " + p_start);
var arr = filterData(rows);
p_end = new Date().getTime();
console.log("finish process: " + p_end);
console.log("process duration : " + ((p_end - p_start) / 1000) + "s");
plot_graph(arr, tab);
}
function filterData(data) {
var arr = [];
for (i = 0; i < data.length; i++) {
var to_seconds = moment(data[i].TIMESTAMP, 'YYYY-MM-DD').unix() * 1000;
if (typeof arr[data[i].PRIORITY] == 'undefined' && !(arr[data[i].PRIORITY] instanceof Array)) {
arr[data[i].PRIORITY] = [];
}
arr[data[i].PRIORITY].push({
0: to_seconds,
1: parseInt(data[i].VALUE)
});
}
return arr;
}
function plot_graph(arr, id) {
var stack = 0,
bars = true,
lines = false,
steps = false;
var data = [{
stack: stack,
lines: {
show: lines,
fill: true,
steps: steps
},
bars: {
show: bars,
barWidth: 0.6
},
"points": {
"show": false
},
data: arr
}];
console.log(data);
$.plot("#" + id + "network-graph", data, {
series: {
stack: stack,
lines: {
show: lines,
fill: true,
steps: steps
},
bars: {
show: bars,
barWidth: 0.6
}
},
xaxis: {
mode: "time",
timeformat: "%y/%m/%d"
}
});
}发布于 2015-12-21 12:16:25
我设法修好了。https://jsfiddle.net/shorif2000/epnv9wrw/。我不得不循环数组对象并为它创建标签。
var datasets = [];
var i = 0;
for (var key in arr) {
datasets.push({label:key,data:arr[key],color:i});
++i;
} https://stackoverflow.com/questions/34394564
复制相似问题