HTMLcopy
1
<button onclick="winter()">Winter Sales</button>
2
<button onclick="spring()">Spring Sales</button>
3
<button onclick="summer()">Summer Sales</button>
4
<button onclick="autumn()">Autumn Sales</button>
5
<div id="container"></div>
CSScopy
9
1
html, body, #container {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// set stage
4
stage = anychart.graphics.create("container");
5
6
// set layers
7
8
//for the Winter Sales chart
9
layer_1 = stage.layer();
10
layer_1.zIndex(80);
11
//for the Spring Sales chart
12
layer_2 = stage.layer();
13
//for the Summer Sales chart
14
layer_3 = stage.layer();
15
//for the Fall Sales chart
16
layer_4 = stage.layer();
17
//for the buttons
18
layer_5 = stage.layer();
19
layer_5.zIndex(100);
20
21
// set data for the Winter Sales
22
var data_1 = [
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
// set data for the Spring Sales
42
var data_2 = [
43
{x: "Ice-Cream", value: 10000, fill:"#FFCC99"},
44
{x: "Sweets", value: 12000, fill:"#F2BFB2"},
45
{x: "Chocolates", value: 13000, fill:"#E6B2CC"},
46
{x: "Hot chocolate", value: 6000, fill:"#D9A6E6"},
47
{x: "Cookies", value: 3000, fill:"#CC99FF"}
48
];
49
50
// set series data
51
var chart_2 = anychart.column();
52
chart_2.title("Spring Sales");
53
chart_2.padding(50, 0, 0, 0);
54
var series_2 = chart_2.column(data_2);
55
series_2.stroke(null);
56
57
// draw
58
chart_2.container(layer_2).draw();
59
60
//set data for the Summer Sales
61
var data_3 = [
62
{x: "Ice-Cream", value: 16350, fill:"#CCFF33"},
63
{x: "Sweets", value: 8930, fill:"#99EF50"},
64
{x: "Chocolates", value: 3400, fill:"#66DF6C"},
65
{x: "Hot chocolate", value: 2780, fill:"#33CF88"},
66
{x: "Cookies", value: 2000, fill:"#00bfa5"}
67
];
68
69
// set series data
70
var chart_3 = anychart.column();
71
chart_3.title("Summer Sales");
72
chart_3.padding(50, 0, 0, 0);
73
var series_3 = chart_3.column(data_3);
74
series_3.stroke(null);
75
76
// draw
77
chart_3.container(layer_3).draw();
78
79
var data_4 = [
80
{x: "Ice-Cream", value: 5000, fill:"#ffa000"},
81
{x: "Sweets", value: 7000, fill:"#DF7800"},
82
{x: "Chocolates", value: 8440, fill:"#C05000"},
83
{x: "Hot chocolate", value: 9800, fill:"#A02800"},
84
{x: "Cookies", value: 10250, fill:"#800000"}
85
];
86
87
88
// set series data
89
var chart_4 = anychart.column();
90
chart_4.title("Fall Sales");
91
chart_4.padding(50, 0, 0, 0);
92
var series_4 = chart_4.column(data_4);
93
series_4.stroke(null);
94
95
// draw
96
chart_4.container(layer_4).draw();
97
98
layer_1.remove();
99
layer_2.remove();
100
layer_3.remove();
101
layer_4.remove();
102
layer_5.remove();
103
});
104
105
function winter() {
106
stage.suspend();
107
stage.addChild(layer_1);
108
layer_2.remove();
109
layer_3.remove();
110
layer_4.remove();
111
stage.resume();
112
};
113
114
function spring() {
115
stage.suspend();
116
stage.addChild(layer_2);
117
layer_1.remove();
118
layer_3.remove();
119
layer_4.remove();
120
stage.resume();
121
};
122
123
function summer() {
124
stage.suspend();
125
stage.addChild(layer_3);
126
layer_1.remove();
127
layer_2.remove();
128
layer_4.remove();
129
stage.resume();
130
};
131
132
function autumn() {
133
stage.suspend();
134
stage.addChild(layer_4);
135
layer_1.remove();
136
layer_2.remove();
137
layer_3.remove();
138
stage.resume();
139
};