mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-25 08:23:13 +09:00
Fix messy graph bug due to unsorted x axis
This commit is contained in:
1 parent
e801be3c77
commit
1e287502f8
1 file changed
+10
-1
+10
-1
@@ -55,7 +55,7 @@ function makeGraph(slaveID, selector) {
|
|||||||
chartData[chartData.length] = generateLineChartArray(data, itemNames[o]);
|
chartData[chartData.length] = generateLineChartArray(data, itemNames[o]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(chartData)
|
//console.log(chartData)
|
||||||
drawChart(selector, chartData)
|
drawChart(selector, chartData)
|
||||||
}
|
}
|
||||||
// callback(data);
|
// callback(data);
|
||||||
@@ -96,6 +96,7 @@ function generateLineChartArray(data, nameKey) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
chartData = sortByKey(chartData, "x")
|
||||||
let xyz = {};
|
let xyz = {};
|
||||||
xyz.name = nameKey;
|
xyz.name = nameKey;
|
||||||
xyz.type = "line";
|
xyz.type = "line";
|
||||||
@@ -138,3 +139,11 @@ function drawChart(selector, chartData) {
|
|||||||
// console.log(chart)
|
// console.log(chart)
|
||||||
chart.render();
|
chart.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function to sort arrays of objects after a keys value
|
||||||
|
function sortByKey(array, key) {
|
||||||
|
return array.sort(function(a, b) {
|
||||||
|
var x = Number(a[key]); var y = Number(b[key]);
|
||||||
|
return ((x < y) ? 1 : ((x > y) ? -1 : 0));
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in new issue
Block a user