Browse Source

add second identical y-axis scale on right side

Thomas Buck 5 years ago
parent
commit
0775a42c36
1 changed files with 16 additions and 4 deletions
  1. 16
    4
      index.html

+ 16
- 4
index.html View File

31
                 }
31
                 }
32
             };
32
             };
33
 
33
 
34
-            var createDataset = function(name, data, color) {
34
+            var createDataset = function(name, data, color, id) {
35
                 return {
35
                 return {
36
                     label: name,
36
                     label: name,
37
                     data: data,
37
                     data: data,
38
+                    yAxisID: id,
38
                     backgroundColor: [
39
                     backgroundColor: [
39
                         'rgba(' + color + ', 0)'
40
                         'rgba(' + color + ', 0)'
40
                     ],
41
                     ],
91
 
92
 
92
                 var datasets = [];
93
                 var datasets = [];
93
                 for (var i = 0; i < data.users.length; i++) {
94
                 for (var i = 0; i < data.users.length; i++) {
94
-                    var set = createDataset(data.users[i].name,
95
-                            data.users[i].data, colorFromIndex(i));
96
-                    datasets.push(set);
95
+                    for (var j = 0; j <= 1; j++) {
96
+                        var set = createDataset(data.users[i].name,
97
+                                data.users[i].data, colorFromIndex(i), j ? 'A' : 'B');
98
+                        datasets.push(set);
99
+                    }
97
                 }
100
                 }
98
 
101
 
99
                 var chart = new Chart(ctx, {
102
                 var chart = new Chart(ctx, {
109
                                 time: {
112
                                 time: {
110
                                     unit: 'day'
113
                                     unit: 'day'
111
                                 }
114
                                 }
115
+                            }],
116
+                            yAxes: [{
117
+                                id: 'A',
118
+                                type: 'linear',
119
+                                position: 'left'
120
+                            }, {
121
+                                id: 'B',
122
+                                type: 'linear',
123
+                                position: 'right'
112
                             }]
124
                             }]
113
                         },
125
                         },
114
                         events: [
126
                         events: [

Loading…
Cancel
Save