Softwareprojektmanagement/src/main/webapp/js/shopping_times.js

93 lines
2.7 KiB
JavaScript

let shopping_result;
let shopping_chart = new Chart(document.getElementById("shopping_times_chart"), {
type: 'bar',
data: {
labels: [1, 2, 3, 4, 5],
datasets: [{
label: 'Anzahl verkaufter Artikel',
data: [0, 0, 0, 0, 0],
backgroundColor: [
'rgba(143, 170, 220, 0.9)',
'rgba(143, 170, 220, 0.9)',
'rgba(143, 170, 220, 0.9)',
'rgba(143, 170, 220, 0.9)',
'rgba(143, 170, 220, 0.9)',
'rgba(143, 170, 220, 0.9)',
],
borderColor: [
'rgba(143, 170, 220, 1)',
'rgba(143, 170, 220, 1)',
'rgba(143, 170, 220, 1)',
'rgba(143, 170, 220, 1)',
'rgba(143, 170, 220, 1)',
'rgba(143, 170, 220, 1)',
],
borderWidth: 1
}]
},
options: {
responsive: true,
title: {
display: false,
text: 'Einkaufszeiten'
},
legend: {
display: false
},
scales: {
yAxes: [{
categoryPercentage: 1.0,
barPercentage: 0.5,
ticks: {
beginAtZero: true
}
}],
xAxes: [{
gridLines: {
display: false
},
}]
}
}
});
function updateShoppingTimesChart(id) {
if(typeof id !== 'undefined') {
request('shopping_times', id).then(function (data) {
shopping_result = data;
changeDay();
});
}else request('shopping_times').then(function(data) {
shopping_result = data;
changeDay();
});
}
function changeDay() {
if(typeof shopping_result["Montag"] !== 'undefined') {
let e = document.getElementById("day");
let value = e.options[e.selectedIndex].text;
shopping_chart.data.labels = shopping_result.labels;
shopping_chart.data.datasets[0].data = shopping_result[value];
let max = Math.max.apply(null, shopping_result[value]);
let min = Math.min.apply(null, shopping_result[value]);
let array = [];
shopping_result[value].map(function (value) {
if(value == max)
value = 'rgba(129, 199, 132, 1)';
else if(value == min) {
value = 'rgba(239, 154, 154, 1)';
}
else {
value = 'rgba(143, 170, 220, 0.9)';
}
array.push(value);
});
shopping_chart.data.datasets[0].backgroundColor = array;
shopping_chart.update();
}
}