mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Display of all graphs working
Also added proper clock to the X axis so its readable #35
This commit is contained in:
1 parent
11e3bf7879
commit
1f06d3eb48
1 file changed
+29
-11
+29
-11
@@ -55,25 +55,45 @@ function post(url, data, callback) {
|
|||||||
makeGraph("-496927236", "", function(data){
|
makeGraph("-496927236", "", function(data){
|
||||||
console.log("Building chart with this data:")
|
console.log("Building chart with this data:")
|
||||||
console.log(data)
|
console.log(data)
|
||||||
|
// find keys
|
||||||
|
let itemNames = [];
|
||||||
|
for(let key in data[data.length - 1].data) {
|
||||||
|
itemNames[itemNames.length] = key
|
||||||
|
}
|
||||||
let chartData = [];
|
let chartData = [];
|
||||||
for(let i = 0; i < data.length; i++){
|
for(let o = 0; o < itemNames.length; o++) {
|
||||||
|
if(itemNames[o] != "water"){
|
||||||
|
chartData[chartData.length] = generateLineChartArray(data, itemNames[o]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
console.log(chartData)
|
||||||
|
drawChart("chartContainer", chartData)
|
||||||
|
})
|
||||||
|
|
||||||
|
function generateLineChartArray(data, nameKey) {
|
||||||
|
let chartData = [];
|
||||||
|
for(let i = 0; i < data.length; i++) {
|
||||||
// only show recent data
|
// only show recent data
|
||||||
if(data[i].timestamp > Date.now() - (24*60*60*1000)){
|
if(data[i].timestamp > Date.now() - (24*60*60*1000)){
|
||||||
let y = data[i].data["copper-plate"]
|
let y = data[i].data[nameKey]
|
||||||
if(!data[i].data["copper-plate"]) {
|
if(!data[i].data[nameKey]) {
|
||||||
y = 0
|
y = 0
|
||||||
}
|
}
|
||||||
chartData[chartData.length] = {
|
chartData[chartData.length] = {
|
||||||
/*x: new Date(data[i].timestamp),*/
|
/*x: new Date(data[i].timestamp),*/
|
||||||
x: data[i].timestamp,//new Date(2012, 00, i),
|
x: new Date(data[i].timestamp),//new Date(2012, 00, i),
|
||||||
y: Number(y)
|
y: Number(y)
|
||||||
}
|
}
|
||||||
// console.log(i + " | " + y)
|
// console.log(i + " | " + y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(chartData)
|
let xyz = {};
|
||||||
drawChart("chartContainer", chartData)
|
xyz.type = "spline";
|
||||||
})
|
xyz.dataPoints = chartData;
|
||||||
|
return xyz;
|
||||||
|
}
|
||||||
|
|
||||||
function drawChart(selector, chartData) {
|
function drawChart(selector, chartData) {
|
||||||
// selector is ID of element, ex "chartContainer"
|
// selector is ID of element, ex "chartContainer"
|
||||||
@@ -81,15 +101,13 @@ function drawChart(selector, chartData) {
|
|||||||
title:{
|
title:{
|
||||||
text: "Production graph"
|
text: "Production graph"
|
||||||
},
|
},
|
||||||
axisX: {
|
|
||||||
},
|
|
||||||
axisY:{
|
axisY:{
|
||||||
includeZero: true
|
includeZero: true
|
||||||
},
|
},
|
||||||
data: [{
|
data: chartData/*[{
|
||||||
type: "line",
|
type: "line",
|
||||||
dataPoints: chartData
|
dataPoints: chartData
|
||||||
}]
|
}]*/
|
||||||
});
|
});
|
||||||
// console.log(chart)
|
// console.log(chart)
|
||||||
chart.render();
|
chart.render();
|
||||||
|
|||||||
Reference in new issue
Block a user