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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<script>
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title:{
text: "Evening Sales in a Restaurant"
},
axisX: {
valueFormatString: "DDD"
},
axisY: {
prefix: "$"
},
toolTip: {
shared: true
},
legend:{
cursor: "pointer",
itemclick: toggleDataSeries
},
data: [{
type: "stackedBar",
name: "Meals",
showInLegend: "true",
xValueFormatString: "DD, MMM",
yValueFormatString: "$#,##0",
dataPoints: [
{ x: new Date(2017, 0, 30), y: 56 },
{ x: new Date(2017, 0, 31), y: 45 },
{ x: new Date(2017, 1, 1), y: 71 },
{ x: new Date(2017, 1, 2), y: 41 },
{ x: new Date(2017, 1, 3), y: 60 },
{ x: new Date(2017, 1, 4), y: 75 },
{ x: new Date(2017, 1, 5), y: 98 }
]
},
{
type: "stackedBar",
name: "Snacks",
showInLegend: "true",
xValueFormatString: "DD, MMM",
yValueFormatString: "$#,##0",
dataPoints: [
{ x: new Date(2017, 0, 30), y: 86 },
{ x: new Date(2017, 0, 31), y: 95 },
{ x: new Date(2017, 1, 1), y: 71 },
{ x: new Date(2017, 1, 2), y: 58 },
{ x: new Date(2017, 1, 3), y: 60 },
{ x: new Date(2017, 1, 4), y: 65 },
{ x: new Date(2017, 1, 5), y: 89 }
]
},
{
type: "stackedBar",
name: "Drinks",
showInLegend: "true",
xValueFormatString: "DD, MMM",
yValueFormatString: "$#,##0",
dataPoints: [
{ x: new Date(2017, 0, 30), y: 48 },
{ x: new Date(2017, 0, 31), y: 45 },
{ x: new Date(2017, 1, 1), y: 41 },
{ x: new Date(2017, 1, 2), y: 55 },
{ x: new Date(2017, 1, 3), y: 80 },
{ x: new Date(2017, 1, 4), y: 85 },
{ x: new Date(2017, 1, 5), y: 83 }
]
},
{
type: "stackedBar",
name: "Dessert",
showInLegend: "true",
xValueFormatString: "DD, MMM",
yValueFormatString: "$#,##0",
dataPoints: [
{ x: new Date(2017, 0, 30), y: 61 },
{ x: new Date(2017, 0, 31), y: 55 },
{ x: new Date(2017, 1, 1), y: 61 },
{ x: new Date(2017, 1, 2), y: 75 },
{ x: new Date(2017, 1, 3), y: 80 },
{ x: new Date(2017, 1, 4), y: 85 },
{ x: new Date(2017, 1, 5), y: 105 }
]
},
{
type: "stackedBar",
name: "Takeaway",
showInLegend: "true",
xValueFormatString: "DD, MMM",
yValueFormatString: "$#,##0",
dataPoints: [
{ x: new Date(2017, 0, 30), y: 52 },
{ x: new Date(2017, 0, 31), y: 55 },
{ x: new Date(2017, 1, 1), y: 20 },
{ x: new Date(2017, 1, 2), y: 35 },
{ x: new Date(2017, 1, 3), y: 30 },
{ x: new Date(2017, 1, 4), y: 45 },
{ x: new Date(2017, 1, 5), y: 25 }
]
}]
});
chart.render();
function toggleDataSeries(e) {
if(typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
e.dataSeries.visible = false;
}
else {
e.dataSeries.visible = true;
}
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>