49 lines
903 B
JavaScript
49 lines
903 B
JavaScript
// Load netDiv.
|
|
const netDiv = document.getElementById("net-stats");
|
|
|
|
// Enter async context. Makes things easier.
|
|
(async function() {
|
|
// Fetch JSON
|
|
const netDataReq = await fetch("/net-in.json");
|
|
const netData = await netDataReq.json();
|
|
|
|
// Get list of entries
|
|
const legends = netData.meta.legend;
|
|
|
|
// Holds the plotly.JS data
|
|
const data = [];
|
|
|
|
// Create date objects for x-axis
|
|
const x = netData.data.map(a => new Date(a[0] * 1e3));
|
|
|
|
// Iterate through legends, fill up data.
|
|
for (let i = 0; i < legends.length; i++) {
|
|
const name = legends[i];
|
|
const y = netData.data.map(a => a[i+1]);
|
|
|
|
// Add data entry to array.
|
|
data.push({
|
|
x,
|
|
y,
|
|
name,
|
|
type: "bar",
|
|
});
|
|
}
|
|
|
|
// Format
|
|
const layout = {
|
|
barmode: "stack",
|
|
title: {
|
|
text: "Traffic In",
|
|
},
|
|
yaxis: {
|
|
title: {
|
|
text: "Bytes/S",
|
|
},
|
|
},
|
|
};
|
|
|
|
// Create plot
|
|
Plotly.newPlot(netDiv, data, layout);
|
|
})()
|