forked from csev/py4e
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgline3.htm
More file actions
106 lines (98 loc) · 3.02 KB
/
gline3.htm
File metadata and controls
106 lines (98 loc) · 3.02 KB
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
<!doctype html>
<html>
<head>
<title>Line Chart</title>
<script src="Chart.bundle.js"></script>
<script src="gline.js"></script>
<style>
canvas {
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
}
</style>
</head>
<body>
<div style="width:75%;">
<canvas id="canvas"></canvas>
</div>
<script>
// Inspired from https://github.com/chartjs/Chart.js/blob/master/samples/line-legend.html
var randomColorFactor = function() {
return Math.round(Math.random() * 255);
};
var randomColor = function(opacity) {
return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
};
// Transform the gline data into Chart.js code
console.log(gline);
info = gline[0];
xaxis_label = info[0];
xaxis = Array();
dsets = Array();
legend = Array();
for(i=1;i<gline.length;i++) {
dset = {};
dset.label = info[i];
console.log(gline[i]);
xaxis[i-1] = gline[i][0];
dset.fill = false;
dset.lineTension = 0;
var background = randomColor(0.5);
dset.borderColor = background;
dset.backgroundColor = background;
dset.pointBorderColor = background;
dset.pointBackgroundColor = background;
dset.pointBorderWidth = 1;
ddata = Array();
for(j=1; j<gline.length; j++ ) {
ddata[j-1] = gline[j][i];
}
dset.data = ddata;
dsets[i-1] = dset;
}
console.log(xaxis);
console.log(dsets);
var config = {
type: 'line',
data: {
labels: xaxis,
datasets: dsets,
},
options: {
responsive: true,
legend: {
position: 'bottom',
},
hover: {
mode: 'label'
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Month'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Value'
}
}]
},
title: {
display: true,
text: 'Sakai Developer Email Participation by Organization'
}
}
};
window.onload = function() {
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = new Chart(ctx, config);
};
</script>
</body>
</html>