HTMLcopy
1
<div id="container"></div>
CSScopy
6
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// set stage
4
var stage = anychart.graphics.create("container");
5
6
// set layers
7
8
//for the Winter Sales chart
9
var layer_1 = stage.layer();
10
layer_1.zIndex(80);
11
//for the Spring Sales chart
12
var layer_2 = stage.layer();
13
//for the Summer Sales chart
14
var layer_3 = stage.layer();
15
//for the Fall Sales chart
16
var layer_4 = stage.layer();
17
//for the buttons
18
var layer_5 = stage.layer();
19
layer_5.zIndex(100);
20
21
22
// set data for the Winter Sales
23
var data_1 = anychart.data.set([
24
{x: "Ice-Cream", value: 5000, fill:"#00FFFF"},
25
{x: "Sweets", value: 10000, fill:"#0DD9E6"},
26
{x: "Chocolates", value: 19000, fill:"#1AB2CC"},
27
{x: "Hot chocolate", value: 16000, fill:"#268CB2"},
28
{x: "Cookies", value: 9000, fill:"#336699"}
29
]);
30
31
// chart type
32
var chart_1 = anychart.column();
33
chart_1.title("Winter Sales");
34
chart_1.padding(50, 0, 0, 0);
35
var series_1 = chart_1.column(data_1);
36
series_1.stroke(null);
37
38
// draw
39
chart_1.container(layer_1).draw();
40
41
42
// set data for the Spring Sales
43
var data_2 = anychart.data.set([
44
{x: "Ice-Cream", value: 10000, fill:"#FFCC99"},
45
{x: "Sweets", value: 12000, fill:"#F2BFB2"},
46
{x: "Chocolates", value: 13000, fill:"#E6B2CC"},
47
{x: "Hot chocolate", value: 6000, fill:"#D9A6E6"},
48
{x: "Cookies", value: 3000, fill:"#CC99FF"}
49
]);
50
51
// set series data
52
var chart_2 = anychart.column();
53
chart_2.title("Spring Sales");
54
chart_2.padding(50, 0, 0, 0);
55
var series_2 = chart_2.column(data_2);
56
series_2.stroke(null);
57
58
// draw
59
chart_2.container(layer_2).draw();
60
61
//set data for the Summer Sales
62
var data_3 = anychart.data.set([
63
{x: "Ice-Cream", value: 16350, fill:"#CCFF33"},
64
{x: "Sweets", value: 8930, fill:"#99EF50"},
65
{x: "Chocolates", value: 3400, fill:"#66DF6C"},
66
{x: "Hot chocolate", value: 2780, fill:"#33CF88"},
67
{x: "Cookies", value: 2000, fill:"#00bfa5"}
68
]);
69
70
// set series data
71
var chart_3 = anychart.column();
72
chart_3.title("Summer Sales");
73
chart_3.padding(50, 0, 0, 0);
74
var series_3 = chart_3.column(data_3);
75
series_3.stroke(null);
76
77
// draw
78
chart_3.container(layer_3);
79
chart_3.draw();
80
81
var data_4 = anychart.data.set([
82
{x: "Ice-Cream", value: 5000, fill:"#FFA000"},
83
{x: "Sweets", value: 7000, fill:"#DF7800"},
84
{x: "Chocolates", value: 8440, fill:"#C05000"},
85
{x: "Hot chocolate", value: 9800, fill:"#A02800"},
86
{x: "Cookies", value: 10250, fill:"#800000"}
87
]);
88
89
90
// set series data
91
var chart_4 = anychart.column();
92
chart_4.title("Fall Sales");
93
chart_4.padding(50, 0, 0, 0);
94
var series_4 = chart_4.column(data_4);
95
series_4.stroke(null);
96
97
// draw
98
chart_4.container(layer_4).draw();
99
100
//buttons
101
var container = document.getElementById("container");
102
var b1 = document.createElement("button");
103
b1.innerHTML = "Winter Sales";
104
container.appendChild(b1);
105
106
b1.style.position = "absolute";
107
b1.style.top = "10px";
108
b1.style.left = "10px";
109
b1.style.width = "120px";
110
111
b1.onclick = function() {
112
stage.suspend();
113
layer_1.zIndex(1000000);
114
layer_2.zIndex(0);
115
layer_3.zIndex(0);
116
layer_4.zIndex(0);
117
stage.resume();
118
};
119
120
var b2 = document.createElement("button");
121
b2.innerHTML = "Spring Sales";
122
container.appendChild(b2);
123
124
b2.style.position = "absolute";
125
b2.style.top = "10px";
126
b2.style.left = "140px";
127
b2.style.width = "120px";
128
b2.onclick = function() {
129
stage.suspend();
130
layer_1.zIndex(0);
131
layer_2.zIndex(1000000);
132
layer_3.zIndex(0);
133
layer_4.zIndex(0);
134
stage.resume();
135
};
136
137
var b3 = document.createElement("button");
138
b3.innerHTML = "Summer Sales";
139
container.appendChild(b3);
140
141
b3.style.position = "absolute";
142
b3.style.top = "10px";
143
b3.style.left = "280px";
144
b3.style.width = "120px";
145
b3.onclick = function() {
146
stage.suspend();
147
layer_1.zIndex(0);
148
layer_2.zIndex(0);
149
layer_3.zIndex(1000000);
150
layer_4.zIndex(0);
151
stage.resume();
152
};
153
154
var b4 = document.createElement("button");
155
b4.innerHTML = "Autumn Sales";
156
container.appendChild(b4);
157
158
b4.style.position = "absolute";
159
b4.style.top = "10px";
160
b4.style.left = "420px";
161
b4.style.width = "120px";
162
163
b4.onclick = function() {
164
stage.suspend();
165
layer_1.zIndex(0);
166
layer_2.zIndex(0);
167
layer_3.zIndex(0);
168
layer_4.zIndex(1000000);
169
stage.resume();
170
};
171
172
});