clean kfet statistic.js

- no longer dictToArray where it isn't necessary (because already an
  array)
- fix chart height:
  - previous charts were causing bugs
  - height is fixed (even with window resizing)
- clean whitespaces
This commit is contained in:
Aurélien Delobelle 2017-04-03 16:53:28 +02:00
parent 87bc90ec8b
commit 903da795ab

View file

@ -22,16 +22,16 @@
return array;
}
function handleTimeChart (dict) {
function handleTimeChart (data) {
// reads the balance data and put it into chartjs formatting
var data = dictToArray(dict, 0);
chart_data = new Array();
for (var i = 0; i < data.length; i++) {
var source = data[i];
data[i] = { x: new Date(source.at),
chart_data[i] = { x: new Date(source.at),
y: source.balance,
label: source.label }
}
return data;
return chart_data;
}
function showStats () {
@ -77,6 +77,7 @@
var chart_options =
{
responsive: true,
maintainAspectRatio: false,
tooltips: {
mode: 'index',
intersect: false,
@ -129,7 +130,7 @@
type: 'line',
options: chart_options,
data: {
labels: dictToArray(data.labels, 1),
labels: (data.labels || []).slice(1),
datasets: chart_datasets,
}
};
@ -137,15 +138,15 @@
// saves the previous charts to be destroyed
var prev_chart = content.children();
// clean
prev_chart.remove();
// creates a blank canvas element and attach it to the DOM
var canvas = $("<canvas height='70'>");
var canvas = $("<canvas height='250'>");
content.append(canvas);
// create the chart
var chart = new Chart(canvas, chart_model);
// clean
prev_chart.remove();
}
// initialize the interface