Bonjour,
J'utilise ChartJS pour générer des graphiques dans une appli web.
Dans un graphique je n'arrive pas à ordonner les jeux de données au niveau de la légende et infos-bulle : l'instruction Order au niveau données permet ça.

Merci pour votre aide.

Voici mon code (j'ai mis un commentaire sur la partie du code concernée) :

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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
new Chart(document.getElementById(canvas).getContext('2d'), {
            type: 'line',
            data: {
                labels: [
                    document.getElementById('annee01').innerHTML,
                    document.getElementById('annee02').innerHTML,
                    document.getElementById('annee03').innerHTML,
                    document.getElementById('annee04').innerHTML,
                    document.getElementById('annee05').innerHTML,
                    document.getElementById('annee06').innerHTML,
                    document.getElementById('annee07').innerHTML,
                    document.getElementById('annee08').innerHTML,
                    document.getElementById('annee09').innerHTML,
                    document.getElementById('annee10').innerHTML,
                    document.getElementById('annee11').innerHTML,
                    document.getElementById('annee12').innerHTML,
                    document.getElementById('annee13').innerHTML,
                    document.getElementById('annee14').innerHTML,
                    document.getElementById('annee15').innerHTML,
                    document.getElementById('annee16').innerHTML,
                    document.getElementById('annee17').innerHTML,
                    document.getElementById('annee18').innerHTML
                ],
                datasets: [{
                        label: 'Evolution des dépenses réelles de fonctionnement',
                        yAxisID: 'right-y-axis',
                        type: 'line',
                        borderColor: colorBleu,
                        backgroundColor: colorBleu,
                        fill: false,
                        order: 3,  //<----------------- Ne fonctionne pas
                        datalabels: { 
                            display: true, 
                            color: 'white',
                            backgroundColor: colorBleu,
                            font: {
                                weight: 'bold'
                            },
                            padding: {
                                top: 1,
                                bottom: 1,
                                left: 3,
                                right: 3
                            },
                            formatter: function (value) {
                                return new Intl.NumberFormat('fr-FR', {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(value) + '%';
                            }
                        },
                        data: [
                            document.getElementById('G1L1Taux01').innerHTML,
                            document.getElementById('G1L1Taux02').innerHTML,
                            document.getElementById('G1L1Taux03').innerHTML,
                            document.getElementById('G1L1Taux04').innerHTML,
                            document.getElementById('G1L1Taux05').innerHTML,
                            document.getElementById('G1L1Taux06').innerHTML,
                            document.getElementById('G1L1Taux07').innerHTML,
                            document.getElementById('G1L1Taux08').innerHTML,
                            document.getElementById('G1L1Taux09').innerHTML,
                            document.getElementById('G1L1Taux10').innerHTML,
                            document.getElementById('G1L1Taux11').innerHTML,
                            document.getElementById('G1L1Taux12').innerHTML,
                            document.getElementById('G1L1Taux13').innerHTML,
                            document.getElementById('G1L1Taux14').innerHTML,
                            document.getElementById('G1L1Taux15').innerHTML,
                            document.getElementById('G1L1Taux16').innerHTML,
                            document.getElementById('G1L1Taux17').innerHTML,
                            document.getElementById('G1L1Taux18').innerHTML
                        ]
                    }, {
                        label: 'Inflation annuelle (Indice INSEE moyenne annuelle)',
                        yAxisID: 'right-y-axis',
                        type: 'line',
                        borderColor: colorGrisFonce,
                        backgroundColor: colorGrisFonce, 
                        fill: false,
                        order: 2,  //<----------------- Ne fonctionne pas
                        datalabels: {
                            display: true,
                            color: 'white',
                            backgroundColor: colorGrisFonce,
                            font: {
                                weight: 'bold'
                            },
                            padding: {
                                top: 1,
                                bottom: 1,
                                left: 3,
                                right: 3
                            },
                            formatter: function (value) {
                                return new Intl.NumberFormat('fr-FR', {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(value) + '%';
                            }
                        },
                        data: [
                            document.getElementById('G1L2Taux01').innerHTML,
                            document.getElementById('G1L2Taux02').innerHTML,
                            document.getElementById('G1L2Taux03').innerHTML,
                            document.getElementById('G1L2Taux04').innerHTML,
                            document.getElementById('G1L2Taux05').innerHTML,
                            document.getElementById('G1L2Taux06').innerHTML,
                            document.getElementById('G1L2Taux07').innerHTML,
                            document.getElementById('G1L2Taux08').innerHTML,
                            document.getElementById('G1L2Taux09').innerHTML,
                            document.getElementById('G1L2Taux10').innerHTML,
                            document.getElementById('G1L2Taux11').innerHTML,
                            document.getElementById('G1L2Taux12').innerHTML
                        ]
                    }, {
                        label: 'Dépenses réelles de fonctionnement',
                        yAxisID: 'left-y-axis',
                        borderColor: colorRouge,
                        backgroundColor: colorRouge, 
                        order: 1,  //<----------------- Ne fonctionne pas
                        datalabels: {
                            display: false
                        },
                        data: [
                            document.getElementById('G1L2Valeur01').innerHTML,
                            document.getElementById('G1L2Valeur02').innerHTML,
                            document.getElementById('G1L2Valeur03').innerHTML,
                            document.getElementById('G1L2Valeur04').innerHTML,
                            document.getElementById('G1L2Valeur05').innerHTML,
                            document.getElementById('G1L2Valeur06').innerHTML,
                            document.getElementById('G1L2Valeur07').innerHTML,
                            document.getElementById('G1L2Valeur08').innerHTML,
                            document.getElementById('G1L2Valeur09').innerHTML,
                            document.getElementById('G1L2Valeur10').innerHTML,
                            document.getElementById('G1L2Valeur11').innerHTML,
                            document.getElementById('G1L2Valeur12').innerHTML,
                            document.getElementById('G1L2Valeur13').innerHTML,
                            document.getElementById('G1L2Valeur14').innerHTML,
                            document.getElementById('G1L2Valeur15').innerHTML,
                            document.getElementById('G1L2Valeur16').innerHTML,
                            document.getElementById('G1L2Valeur17').innerHTML,
                            document.getElementById('G1L2Valeur18').innerHTML
                        ]
                    }]
            },
            options: {
                title: {
                    text: 'Evolution des dépenses réelles de fonctionnement'
                },
                layout: {
                    padding: {
                        right: 15
                    }
                },
                tooltips: {
                    callbacks: {
                        label: function (tooltipItem, data) {
                            bulle = ' ' + data.datasets[tooltipItem.datasetIndex].label + ' : ';
                            if (tooltipItem.datasetIndex === 0) {
                                return bulle + new Intl.NumberFormat('fr-FR', {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(tooltipItem.value) + '%';
                            }
                            if (tooltipItem.datasetIndex === 1) {
                                return bulle + new Intl.NumberFormat('fr-FR', {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(tooltipItem.value) + '%';
                            }
                            if (tooltipItem.datasetIndex === 2) {
                                return bulle + new Intl.NumberFormat('fr', {maximumFractionDigits: 0, style: 'currency', currency: 'EUR'}).format(tooltipItem.value);
                            }
                        }
                    }
                },
                scales: {
                    xAxes: [{
                            gridLines: {
                                display: false
                            }
                        }],
                    yAxes: [{
                            id: 'left-y-axis',
                            type: 'linear',
                            position: 'left',
                            ticks: {
                                callback: function (value) {
                                    return new Intl.NumberFormat('fr-FR').format(value);
                                }
                            }
                        }, {
                            id: 'right-y-axis',
                            type: 'linear',
                            position: 'right',
                            ticks: {
                                callback: function (value) {
                                    return new Intl.NumberFormat('fr-FR', {minimumFractionDigits: 2, maximumFractionDigits: 2}).format(value) + '%';
                                }
                            },
                            gridLines: {
                                display: false
                            }
                        }]
                }
            }
        });
    }