2020-05-18 17:42:23 +00:00
|
|
|
function SingleBarChart(id, name) {
|
|
|
|
var ctx = document.getElementById(id).getContext('2d');
|
|
|
|
this._used = [];
|
|
|
|
this._free = [];
|
|
|
|
this._chart = new Chart(ctx, {
|
2020-06-03 09:15:01 +00:00
|
|
|
type: 'horizontalBar',
|
2020-05-18 17:42:23 +00:00
|
|
|
data: {
|
|
|
|
labels:[name],
|
|
|
|
datasets: [{
|
2020-06-09 10:06:12 +00:00
|
|
|
backgroundColor: "#839496",
|
2020-05-18 17:42:23 +00:00
|
|
|
label: "used",
|
|
|
|
data: this._used,
|
|
|
|
},
|
|
|
|
{
|
2020-06-09 10:06:12 +00:00
|
|
|
backgroundColor: "#859900",
|
2020-05-18 17:42:23 +00:00
|
|
|
label: "free",
|
|
|
|
data: this._free,
|
|
|
|
}],
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
legend: {
|
|
|
|
display: false,
|
|
|
|
},
|
|
|
|
animation: false,
|
|
|
|
scales: {
|
|
|
|
xAxes: [{
|
|
|
|
stacked: true
|
|
|
|
}],
|
|
|
|
yAxes: [{
|
|
|
|
stacked: true,
|
|
|
|
display: true,
|
|
|
|
ticks: {
|
|
|
|
beginAtZero: true,
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
this.update = function (used, free) {
|
|
|
|
this._used.shift();
|
|
|
|
this._free.shift();
|
|
|
|
this._used.push(used);
|
|
|
|
this._free.push(free);
|
|
|
|
|
|
|
|
this._chart.update();
|
|
|
|
};
|
|
|
|
}
|