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
stage = anychart.graphics.create("container");
3
4
var data = [
5
["Apples", 21, 99, 19, 72, 94, 71],
6
["Pears", 41, 7, 71, 10, 27, 79],
7
["Bananas", 9, 15, 77, 58, 97, 79],
8
["Grapes", 71, 34, 40, 21, 72, 6],
9
["Oranges", 6, 29, 11, 46, 19, 49]
10
];
11
12
var chart = anychart.column();
13
14
var series = anychart.data.mapAsTable(data, "value");
15
16
for (var i in series) {
17
chart.column(series[i]);
18
}
19
20
var legend = chart.legend();
21
legend.enabled(true);
22
23
// Set maximum width and height.
24
legend.maxWidth("30%");
25
legend.maxHeight("30%");
26
27
// legend mode and position
28
legend.itemsLayout("verticalExpandable");
29
legend.position("right");
30
31
// paginator position
32
legend.paginator().orientation("bottom");
33
34
35
chart.title("Expandable legend");
36
chart.container(stage);
37
chart.draw();
38
39
createLabel("Click to remove 7 series", 5, function(){
40
chart.removeSeriesAt(chart.getSeriesCount() - 1);
41
});
42
43
createLabel("Click to add 7 series", 180, function(){
44
for (var i in series) {
45
chart.column(series[i]);
46
}
47
});
48
});
49
50
function createLabel(text, offset, action){
51
var lbl = anychart.standalones.label();
52
lbl.background({fill: "#9E9E9E"});
53
lbl.text(text);
54
lbl.fontColor("#fff");
55
lbl.padding(5);
56
lbl.offsetX(offset);
57
lbl.offsetY(5);
58
lbl.listen("mouseOver", function () {
59
document.body.style.cursor = "pointer";
60
});
61
lbl.listen("mouseOut", function () {
62
document.body.style.cursor = "auto";
63
});
64
lbl.listen("click", action);
65
lbl.container(stage);
66
lbl.draw();
67
}