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 = [
8
{x: Date.UTC(2015, 4, 1), open:18.23, high:19.36, low:18.18, close:19.31},
9
{x: Date.UTC(2015, 4, 2), open:19.50, high:19.89, low:19.00, close:19.29},
10
{x: Date.UTC(2015, 4, 3), open:19.13, high:19.15, low:18.43, close:18.75},
11
{x: Date.UTC(2015, 4, 6), open:18.54, high:18.76, low:18.27, close:18.76},
12
{x: Date.UTC(2015, 4, 7), open:18.76, high:19.14, low:18.63, close:18.76}
13
];
14
15
// set the chart type and title
16
var chart = anychart.financial();
17
chart.title("Switching the Series Type");
18
chart.title().padding(25);
19
20
// set the series type
21
var series = chart.ohlc(data);
22
23
// set the chart container and initiate drawing the chart
24
chart.container(stage);
25
chart.draw();
26
27
// create a label for switching to the line series
28
createLabel("Switch to OHLC", 10, function() {
29
// change the series type
30
series.seriesType("ohlc");
31
chart.title("Switching the Series Type \n OHLC");
32
});
33
34
// create a label for switching to the column series
35
createLabel("Switch to Japanese Candlestick", 140, function() {
36
// change the series type
37
series.seriesType("candlestick");
38
chart.title("Switching the Series Type \n Japanese Candlestick");
39
});
40
41
// create a label for switching to the area series
42
createLabel("Switch to Range Area", 375, function() {
43
// change the series type
44
series.seriesType("rangeArea");
45
chart.title("Switching the Series Type \n Range Area");
46
});
47
48
});
49
50
// a helper function for creating buttons
51
function createLabel(text, offset, action){
52
var label = anychart.standalones.label();
53
label.background({fill: "#1976d2"});
54
label.text(text);
55
label.fontColor("#fff");
56
label.padding(5);
57
label.parentBounds(offset, 5, 130, 100);
58
label.listen("click", action);
59
label.container(stage);
60
label.draw();
61
label.listen("mouseOver", function(){
62
label.background().fill("#1976d2 0.5")
63
document.body.style.cursor = "pointer";
64
label.draw();
65
});
66
label.listen("mouseOut", function(){
67
label.background().fill("#1976d2")
68
document.body.style.cursor = "auto";
69
label.draw();
70
});
71
return label;
72
};