Softwareprojektmanagement/src/main/webapp/js/sales.js

71 lines
1.5 KiB
JavaScript

/**
* renders sales numbers as chart.
*
* @author Johannes Theiner
* @version 0.1
* @since 1.0
*/
let top_flop_result;
let sales = new Chart($("#sales_chart"), {
type: 'horizontalBar',
data: {
labels: [],
datasets: [{
data: [],
backgroundColor: [],
}]
},
options: {
tooltips: {
callbacks: {
label: function (tooltipItems, data) {
return tooltipItems.xLabel + ' Stück';
}
},
},
responsive: true,
title: {
display: false
},
legend: {
display: false
},
scales: {
yAxes: [{
gridLines: {
display: false
},
ticks: {
beginAtZero: true
}
}]
}
}
});
function updateTopFlopChart(id) {
if (typeof id !== 'undefined') {
request('sales', id).then(function (data) {
top_flop_result = data;
updateTopFlop();
});
} else request('sales').then(function (data) {
top_flop_result = data;
updateTopFlop();
});
}
function updateTopFlop() {
sales.data.labels = top_flop_result.labels;
sales.data.datasets[0].data = top_flop_result.data;
let seq = palette('mpn65', 15);
for (let i = 0; i < 15; i++) {
sales.data.datasets[0].backgroundColor[i] = "#" + seq[i];
}
sales.update();
}