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
// set data for the Winter Sales
22
var data_1 = anychart.data.set([
23
{x: "Ice-Cream", value: 5000, fill:"#00FFFF"},
24
{x: "Sweets", value: 10000, fill:"#0DD9E6"},
25
{x: "Chocolates", value: 19000, fill:"#1AB2CC"},
26
{x: "Hot chocolate", value: 16000, fill:"#268CB2"},
27
{x: "Cookies", value: 9000, fill:"#336699"}
28
]);
29
30
// chart type
31
var chart_1 = anychart.column();
32
chart_1.title("Winter Sales");
33
chart_1.padding(50, 0, 0, 0);
34
var series_1 = chart_1.column(data_1);
35
series_1.fill(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
62
//set data for the Summer Sales
63
var data_3 = anychart.data.set([
64
{x: "Ice-Cream", value: 16350, fill:"#CCFF33"},
65
{x: "Sweets", value: 8930, fill:"#99EF50"},
66
{x: "Chocolates", value: 3400, fill:"#66DF6C"},
67
{x: "Hot chocolate", value: 2780, fill:"#33CF88"},
68
{x: "Cookies", value: 2000, fill:"#00bfa5"}
69
]);
70
71
// set series data
72
var chart_3 = anychart.column();
73
chart_3.title("Summer Sales");
74
chart_3.padding(50, 0, 0, 0);
75
var series_3 = chart_3.column(data_3);
76
series_3.stroke(null);
77
78
// draw
79
chart_3.container(layer_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
layer_1.remove();
101
layer_2.remove();
102
layer_3.remove();
103
layer_4.remove();
104
layer_5.remove();
105
106
107
//buttons
108
var container = document.getElementById("container");
109
var b1 = document.createElement("button");
110
b1.innerHTML = "Winter Sales";
111
container.appendChild(b1);
112
113
b1.style.position = "absolute";
114
b1.style.top = "10px";
115
b1.style.left = "10px";
116
b1.style.width = "120px";
117
118
b1.onclick = function() {
119
stage.suspend();
120
stage.addChild(layer_1);
121
layer_2.remove();
122
layer_3.remove();
123
layer_4.remove();
124
stage.resume();
125
};
126
127
var b2 = document.createElement("button");
128
b2.innerHTML = "Spring Sales";
129
container.appendChild(b2);
130
131
b2.style.position = "absolute";
132
b2.style.top = "10px";
133
b2.style.left = "140px";
134
b2.style.width = "120px";
135
136
b2.onclick = function() {
137
stage.suspend();
138
stage.addChild(layer_2);
139
layer_1.remove();
140
layer_3.remove();
141
layer_4.remove();
142
stage.resume();
143
};
144
145
var b3 = document.createElement("button");
146
b3.innerHTML = "Summer Sales";
147
container.appendChild(b3);
148
149
b3.style.position = "absolute";
150
b3.style.top = "10px";
151
b3.style.left = "280px";
152
b3.style.width = "120px";
153
154
b3.onclick = function() {
155
stage.suspend();
156
stage.addChild(layer_3);
157
layer_1.remove();
158
layer_2.remove();
159
layer_4.remove();
160
stage.resume();
161
};
162
163
var b4 = document.createElement("button");
164
b4.innerHTML = "Autumn Sales";
165
container.appendChild(b4);
166
167
b4.style.position = "absolute";
168
b4.style.top = "10px";
169
b4.style.left = "420px";
170
b4.style.width = "120px";
171
172
b4.onclick = function() {
173
stage.suspend();
174
stage.addChild(layer_4);
175
layer_1.remove();
176
layer_2.remove();
177
layer_3.remove();
178
stage.resume();
179
};
180
181
});