1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
function BuildBarChart(result) {
var ctx = document.getElementById('myChart').getContext('2d');
DaysInTheMonthString = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];
// const TotalTicketsPerDay = [0,0,0,0,0,0,0,0,5,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
const TotalTicketsPerDay = JSON.parse(result);
var chart = new Chart(ctx, {
// The type of chart we want to create
type: 'bar',
// The data for our dataset
data: {
labels: DaysInTheMonthString,
datasets: [{
label: 'Total tickets this month',
backgroundColor: 'rgb(2, 117, 216)',
borderColor: 'rgb(2, 117, 216)',
data: TotalTicketsPerDay
}]
},
// Configuration options go here
options: {
maintainAspectRatio: false,
layout: {
padding: {
left: 0,
right: 15,
top: 25,
bottom: 0
}
},
scales: {
xAxes: [{
time: {
unit: ''
},
gridLines: {
display: true,
drawBorder: false
},
ticks: {
maxTicksLimit: 31
},
maxBarThickness: 5,
}],
yAxes: [{
ticks: {
min: 0,
max: 5,
maxTicksLimit: 5,
padding: 1,
// Include a dollar sign in the ticks
callback: function (value, index, values) {
return number_format(value);
}
},
gridLines: {
color: "rgb(234, 236, 244)",
zeroLineColor: "rgb(234, 236, 244)",
drawBorder: false,
borderDash: [2],
zeroLineBorderDash: [2]
}
}],
},
legend: {
display: true
},
tooltips: {
titleMarginBottom: 10,
titleFontColor: '#6e707e',
titleFontSize: 14,
backgroundColor: "rgb(255,255,255)",
bodyFontColor: "#858796",
borderColor: '#dddfeb',
borderWidth: 1,
xPadding: 15,
yPadding: 15,
displayColors: false,
caretPadding: 10,
callbacks: {
label: function (tooltipItem, chart) {
var datasetLabel = chart.datasets[tooltipItem.datasetIndex].label || '';
return datasetLabel + ": " + number_format(tooltipItem.yLabel);
}
}
},
}
});
} |
Partager