-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
118 lines (102 loc) · 3.06 KB
/
script.js
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
var TITLE = 'Hartford School District is No Longer Largest in Connecticut';
// x-axis label and label in tooltip
var X_AXIS = 'Academic Year';
// y-axis label and label in tooltip
var Y_AXIS = 'Number of Students';
// Should y-axis start from 0? `true` or `false`
var BEGIN_AT_ZERO = false;
// `true` to show the grid, `false` to hide
var SHOW_GRID = true;
// `true` to show the legend, `false` to hide
var SHOW_LEGEND = true;
$(document).ready(function() {
// Read data file with random string generated by current time
// to bypass browser cache, and create chart
$.get('./data.csv', {'_': $.now()}, function(csvString) {
var data = Papa.parse(csvString).data;
var timeLabels = data.slice(1).map(function(row) { return row[0]; });
var datasets = [];
for (var i = 1; i < data[0].length; i++) {
datasets.push(
{
label: data[0][i], // column name
data: data.slice(1).map(function(row) {return row[i]}), // data in that column
fill: false // `true` for area charts, `false` for regular line charts
}
)
}
// Get container for the chart
var ctx = document.getElementById('chart-container').getContext('2d');
new Chart(ctx, {
type: 'line',
data: {
labels: timeLabels,
datasets: datasets,
},
options: {
title: {
display: true,
text: TITLE,
fontSize: 14,
},
legend: {
display: SHOW_LEGEND,
},
maintainAspectRatio: false,
scales: {
xAxes: [{
scaleLabel: {
display: X_AXIS !== '',
labelString: X_AXIS
},
gridLines: {
display: SHOW_GRID,
},
ticks: {
maxTicksLimit: 10,
callback: function(value, index, values) {
return value.toLocaleString();
}
}
}],
yAxes: [{
stacked: false, // `true` for stacked area chart, `false` otherwise
beginAtZero: true,
scaleLabel: {
display: Y_AXIS !== '',
labelString: Y_AXIS
},
gridLines: {
display: SHOW_GRID,
},
ticks: {
maxTicksLimit: 10,
beginAtZero: BEGIN_AT_ZERO,
callback: function(value, index, values) {
return value.toLocaleString()
}
}
}]
},
tooltips: {
displayColors: false,
callbacks: {
label: function(tooltipItem, all) {
return all.datasets[tooltipItem.datasetIndex].label
+ ': ' + tooltipItem.yLabel.toLocaleString();
}
}
},
plugins: {
colorschemes: {
/*
Replace below with any other scheme from
https://nagix.github.io/chartjs-plugin-colorschemes/colorchart.html
*/
scheme: 'brewer.DarkTwo5'
}
}
}
});
});
});