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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
theme: "light2",
title: {
text: "Daily Temperature Variation in Bengaluru - July 2017"
},
axisX: {
valueFormatString: "DD MMM"
},
axisY: {
title: "Temperature (in °C)"
},
toolTip: {
shared: true
},
legend: {
dockInsidePlotArea: true,
cursor: "pointer",
itemclick: toggleDataSeries
},
data: [{
type: "rangeArea",
markerSize: 0,
name: "Temperature Range",
showInLegend: true,
toolTipContent: "{x}<br><span style='color:#6D77AC'>{name}</span><br>Min: {y[1]} °C<br>Max: {y[0]} °C",
dataPoints: [
{ x: new Date(2017, 6, 1), y: [30, 19] },
{ x: new Date(2017, 6, 2), y: [30, 21] },
{ x: new Date(2017, 6, 3), y: [29, 21] },
{ x: new Date(2017, 6, 4), y: [28, 20] },
{ x: new Date(2017, 6, 5), y: [29, 20] },
{ x: new Date(2017, 6, 6), y: [29, 20] },
{ x: new Date(2017, 6, 7), y: [27, 21] },
{ x: new Date(2017, 6, 8), y: [26, 20] },
{ x: new Date(2017, 6, 9), y: [30, 20] },
{ x: new Date(2017, 6, 10), y: [30, 21] },
{ x: new Date(2017, 6, 11), y: [30, 21] },
{ x: new Date(2017, 6, 12),y: [29, 21] },
{ x: new Date(2017, 6, 13),y: [27, 20] },
{ x: new Date(2017, 6, 14),y: [27, 20] },
{ x: new Date(2017, 6, 15),y: [25, 20] },
{ x: new Date(2017, 6, 16),y: [29, 20] },
{ x: new Date(2017, 6, 17),y: [28, 20] },
{ x: new Date(2017, 6, 18),y: [27, 21] },
{ x: new Date(2017, 6, 19),y: [27, 21] },
{ x: new Date(2017, 6, 20),y: [29, 21] },
{ x: new Date(2017, 6, 21),y: [29, 20] },
{ x: new Date(2017, 6, 22),y: [31, 20] },
{ x: new Date(2017, 6, 23),y: [30, 21] },
{ x: new Date(2017, 6, 24),y: [30, 20] },
{ x: new Date(2017, 6, 25),y: [31, 21] },
{ x: new Date(2017, 6, 26),y: [30, 21] },
{ x: new Date(2017, 6, 27),y: [31, 21] },
{ x: new Date(2017, 6, 28),y: [31, 21] },
{ x: new Date(2017, 6, 29),y: [31, 21] },
{ x: new Date(2017, 6, 30), y: [31, 21] },
{ x: new Date(2017, 6, 31), y: [31, 22] }
]
}]
});
chart.render();
addAverages();
function addAverages() {
var dps = [];
for(var i = 0; i < chart.options.data[0].dataPoints.length; i++) {
dps.push({
x: chart.options.data[0].dataPoints[i].x,
y: (chart.options.data[0].dataPoints[i].y[0] + chart.options.data[0].dataPoints[i].y[1]) / 2
});
}
chart.options.data.push({
type: "line",
name: "Average",
showInLegend: true,
markerType: "triangle",
markerSize: 0,
yValueFormatString: "##.0 °C",
dataPoints: dps
});
chart.render();
}
function toggleDataSeries(e) {
if (typeof (e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
} else {
e.dataSeries.visible = true;
}
e.chart.render();
}
}
</script>
</head>
<body>
<div id="chartContainer" style="height: 370px; max-width: 920px; margin: 0px auto;"></div>
<script src="../../asset/js/canvasjs/canvasjs.min.js"></script>
</body>
</html>