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.stroke(null);
36
37
// draw
38
chart_1.container(layer_1).draw();
39
40
// set data for the Spring Sales
41
var data_2 = [
42
{x: "Ice-Cream", value: 10000, fill:"#FFCC99"},
43
{x: "Sweets", value: 12000, fill:"#F2BFB2"},
44
{x: "Chocolates", value: 13000, fill:"#E6B2CC"},
45
{x: "Hot chocolate", value: 6000, fill:"#D9A6E6"},
46
{x: "Cookies", value: 3000, fill:"#CC99FF"}
47
];
48
49
// set series data
50
var chart_2 = anychart.column();
51
chart_2.title("Spring Sales");
52
chart_2.padding(50, 0, 0, 0);
53
var series_2 = chart_2.column(data_2);
54
series_2.stroke(null);
55
56
// draw
57
chart_2.container(layer_2).draw();
58
59
//set data for the Summer Sales
60
var data_3 = [
61
{x: "Ice-Cream", value: 16350, fill:"#CCFF33"},
62
{x: "Sweets", value: 8930, fill:"#99EF50"},
63
{x: "Chocolates", value: 3400, fill:"#66DF6C"},
64
{x: "Hot chocolate", value: 2780, fill:"#33CF88"},
65
{x: "Cookies", value: 2000, fill:"#00bfa5"}
66
];
67
68
// set series data
69
var chart_3 = anychart.column();
70
chart_3.title("Summer Sales");
71
chart_3.padding(50, 0, 0, 0);
72
var series_3 = chart_3.column(data_3);
73
series_3.stroke(null);
74
75
// draw
76
chart_3.container(layer_3);
77
chart_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
99
function winter() {
100
stage.suspend();
101
layer_1.zIndex(1000000);
102
layer_2.zIndex(0);
103
layer_3.zIndex(0);
104
layer_4.zIndex(0);
105
stage.resume();
106
};
107
108
function spring() {
109
stage.suspend();
110
layer_1.zIndex(0);
111
layer_2.zIndex(1000000);
112
layer_3.zIndex(0);
113
layer_4.zIndex(0);
114
stage.resume();
115
};
116
117
function summer() {
118
stage.suspend();
119
layer_1.zIndex(0);
120
layer_2.zIndex(0);
121
layer_3.zIndex(1000000);
122
layer_4.zIndex(0);
123
stage.resume();
124
};
125
126
function autumn() {
127
stage.suspend();
128
layer_1.zIndex(0);
129
layer_2.zIndex(0);
130
layer_3.zIndex(0);
131
layer_4.zIndex(1000000);
132
stage.resume();
133
};