-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
150 lines (141 loc) · 4.49 KB
/
index.php
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
<?php
include 'src/helpers.php';
include 'src/RandomColor.php';
use \Colors\RandomColor;
// open csv
$arrCSV = openCSV("data/2010-2017 MCIAA Passenger movement monthly.csv");
// use as chart colors
$arrColor = [
RandomColor::one(array('luminosity'=>'dark','hue'=>'red','format'=>'rgbCss')),
RandomColor::one(array('luminosity'=>'dark','hue'=>'blue','format'=>'rgbCss')),
RandomColor::one(array('luminosity'=>'dark','hue'=>'orange','format'=>'rgbCss')),
RandomColor::one(array('luminosity'=>'dark','hue'=>'pink','format'=>'rgbCss'))
];
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/basscss.min.css">
<link rel="stylesheet" href="css/main.css">
<title>Chart JS | MCIAA Passenger movement monthly</title>
</head>
<body>
<div class="container">
<label for="pattern-switch">
<input type="checkbox" id="pattern-switch">Toggle patterns
</label>
<canvas id="chartHolder"></canvas>
</div>
<!-- http://www.chartjs.org/ and https://github.com/ashiguruma/patternomaly/ plugin -->
<script src="js/vendor/Chart.min.js"></script>
<script src='js/vendor/patternomaly.js'></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/vendor/jquery.min.js"><\/script>')
</script>
<script src="js/vendor/bootstrap.min.js"></script>
<script>
Chart.defaults.global.defaultFontColor = '#777';
let color = Chart.helpers.color;
let colors = <?php echo json_encode($arrColor) ?>;
let patterns = pattern.generate(colors);
function createConfig() {
return {
type: 'bar',
data: {
labels: <?php echo json_encode($arrCSV['month']); ?>,
datasets: [
{
label: '# of Passengers in 2014',
data: <?php echo json_encode($arrCSV['2014'], JSON_NUMERIC_CHECK); ?>,
backgroundColor: color(colors[0]).alpha(0.9).rgbString(),
borderColor: colors[0]
},
{
label: '# of Passengers in 2015',
data: <?php echo json_encode($arrCSV['2015'], JSON_NUMERIC_CHECK); ?>,
backgroundColor: color(colors[1]).alpha(0.9).rgbString(),
borderColor: colors[1]
},
{
label: '# of Passengers in 2016',
data: <?php echo json_encode($arrCSV['2016'], JSON_NUMERIC_CHECK); ?>,
backgroundColor: color(colors[2]).alpha(0.9).rgbString(),
borderColor: colors[2]
},
{
label: '# of Passengers in 2017',
data: <?php echo json_encode($arrCSV['2017'], JSON_NUMERIC_CHECK); ?>,
backgroundColor: color(colors[3]).alpha(0.9).rgbString(),
borderColor: colors[3]
}],
},
options: {
animation: {
duration: 2000,
},
title: {
display: true,
text: 'MCIAA Passenger movement monthly',
fontSize: 32,
fontColor: '#333'
},
layout: {
padding: {
bottom: 10
}
},
responsive: true,
scaleShowValues: true,
scales: {
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Amount',
fontSize: 24,
fontColor: '#333'
},
ticks: {
beginAtZero: true
}
}],
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Month',
fontSize: 24,
fontColor: '#333'
},
ticks: {
autoSkip: false
}
}]
},
tooltips: {
position: 'average',
mode: 'index',
intersect: false
}
}
};
}
// init chart
let ctx = document.getElementById("chartHolder").getContext('2d');
let config = createConfig();
let mciaaBarChart = new Chart(ctx, config);
// toggle to add pattern
let patternSwitch = document.querySelector('#pattern-switch');
patternSwitch.addEventListener('change', function (e) {
let fill = (e.currentTarget.checked) ? patterns : colors;
for(let i in mciaaBarChart.data.datasets){
mciaaBarChart.data.datasets[i].backgroundColor = (e.currentTarget.checked) ? fill[i] : color(fill[i]).alpha(0.9).rgbString();
}
mciaaBarChart.update();
});
</script>
</body>
</html>