Bonjour à tous
J’ai des données que j’utilise pour obtenir des totaux et ainsi alimenter un chart.js .
Ça marche très bien avec : (voir data: TotalTicketsPerDay)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 function BuildBarChart() { 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]; // 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 open this month', backgroundColor: 'rgb(2, 117, 216)', borderColor: 'rgb(2, 117, 216)', data: TotalTicketsPerDay }] },
Malheureusement j’ai besoin d’utiliser une variable a la place car les résultats vont changer tous les jours.
Le résultat se trouve dans une variable et se représente comme ceci :
[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]
Si j’utilise une variable pour représenter ce string de résultats ça ne marche pas.
Et si je fais
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 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]; 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 open this month', backgroundColor: 'rgb(2, 117, 216)', borderColor: 'rgb(2, 117, 216)', data: result }] },
Ça ne marche pas non plus.
Code : Sélectionner tout - Visualiser dans une fenêtre à part const TotalTicketsPerDay = result ;
Quelqu’un a une idée pour résoudre ce problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 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 = 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 open this month', backgroundColor: 'rgb(2, 117, 216)', borderColor: 'rgb(2, 117, 216)', data: TotalTicketsPerDay }] },
Merci
Partager