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
// create a stage
4
stage = anychart.graphics.create("container");
5
6
// set the data
7
var data = anychart.data.set([
8
["Spring", 10], ["Summer", 15], ["Autumn", 8], ["Winter", 23]
9
]);
10
11
// set the chart type and title
12
var chart = anychart.line();
13
chart.title("Switching the Series Type");
14
chart.title().padding(25);
15
16
// set the series type
17
var series = chart.line(data);
18
19
// set the chart container and initiate drawing the chart
20
chart.container(stage);
21
chart.draw();
22
23
// create a label for switching to the line series
24
createLabel("Switch to Line", 10, function() {
25
// change the series type
26
series.seriesType("line");
27
chart.title("Switching the Series Type \n Line");
28
});
29
30
// create a label for switching to the column series
31
createLabel("Switch to Column", 127, function() {
32
// change the series type
33
series.seriesType("column");
34
chart.title("Switching the Series Type \n Column");
35
});
36
37
// create a label for switching to the area series
38
createLabel("Switch to Area", 265, function() {
39
// change the series type
40
series.seriesType("area");
41
chart.title("Switching the Series Type \n Area");
42
});
43
44
});
45
46
// a helper function for creating buttons
47
function createLabel(text, offset, action){
48
var label = anychart.standalones.label();
49
label.background({fill: "#1976d2"});
50
label.text(text);
51
label.fontColor("#fff");
52
label.padding(5);
53
label.parentBounds(offset, 5, 130, 100);
54
label.listen("click", action);
55
label.container(stage);
56
label.draw();
57
label.listen("mouseOver", function(){
58
label.background().fill("#1976d2 0.5")
59
document.body.style.cursor = "pointer";
60
label.draw();
61
});
62
label.listen("mouseOut", function(){
63
label.background().fill("#1976d2")
64
document.body.style.cursor = "auto";
65
label.draw();
66
});
67
return label;
68
};