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
// data
4
var data = anychart.data.set([
5
["Department Stores", 637166, 737166, 813000, 719242, 791736, 837164, 918364, 819363, 864213],
6
["Discount Stores", 721630, 537166, 128013, 471946, 385638, 764426, 237561, 628452 ,721645],
7
["Men's/Women's Specialty Stores", 148662, 188662, 194912, 573173, 384617, 481627, 615373, 274618 ,471846],
8
["Juvenile Specialty Stores", 78662, 178662, 612037, 589275, 128614, 201385, 171284, 317394 ,172846],
9
["All other outlets", 90000, 89000, 375913, 183613, 100847, 92714, 192483, 137184 ,99128]
10
]);
11
12
// remapping data
13
var Sales2003 = data.mapAs({x: [0], value: [1]});
14
var Sales2004 = data.mapAs({x: [0], value: [2]});
15
var Sales2005 = data.mapAs({x: [0], value: [3]});
16
17
// define chart type
18
var chart = anychart.cartesian();
19
20
// set default series type
21
chart.defaultSeriesType("column");
22
23
// create multiple series
24
chart.addSeries(Sales2003, Sales2004, Sales2005);
25
26
// set title
27
chart.title("Add/Remove Series sample");
28
29
// set axes titles
30
var xAxis = chart.xAxis();
31
xAxis.title("Retail Channel");
32
var yAxis = chart.yAxis();
33
yAxis.title("Sales");
34
35
var add = chart.label(0);
36
add.padding(5,5);
37
add.position("topLeft");
38
add.anchor("topLeft");
39
add.offsetY(10);
40
add.offsetX(10);
41
add.text("Add Series");
42
var addBg = add.background();
43
addBg.enabled(true);
44
addBg.stroke("2 #BCBCBC");
45
addBg.cornerType("round");
46
addBg.corners(5);
47
add.listen("click",function(){
48
if (chart.getSeriesCount()<9)
49
chart.addSeries(data.mapAs({x: [0], value: [chart.getSeriesCount()+1]}));
50
});
51
var remove = chart.label(1);
52
remove.padding(5,5);
53
remove.position("topLeft");
54
remove.anchor("topLeft");
55
remove.offsetY(45);
56
remove.offsetX(10);
57
remove.text("Remove Series");
58
var removeBg = remove.background();
59
removeBg.enabled(true);
60
removeBg.stroke("2 #BCBCBC");
61
removeBg.cornerType("round");
62
removeBg.corners(5);
63
remove.listen("click",function(){
64
if (chart.getSeriesCount()>0)
65
chart.removeSeriesAt(chart.getSeriesCount()-1);
66
});
67
var removeAll = chart.label(2);
68
removeAll.padding(5,5);
69
removeAll.position("topLeft");
70
removeAll.anchor("topLeft");
71
removeAll.offsetY(80);
72
removeAll.offsetX(10);
73
removeAll.text("Remove All Series");
74
var removeAllBg = removeAll.background();
75
removeAllBg.enabled(true);
76
removeAllBg.stroke("2 #BCBCBC");
77
removeAllBg.cornerType("round");
78
removeAllBg.corners(5);
79
removeAll.listen("click",function(){
80
chart.removeAllSeries();
81
});
82
83
// draw chart
84
chart.container("container");
85
chart.draw();
86
});