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 table = anychart.data.table('x');
8
table.addData(data_acme_stock());
9
10
// map the data
11
mapping = table.mapAs({'open':"o",'high': "h", 'low':"l", 'close':"c"});
12
var chart = anychart.stock();
13
14
// set the series type and title
15
var series = chart.plot(0).ohlc(mapping);
16
series.name("ACME Corp. stock prices");
17
18
// format y-axis labels
19
chart.plot(0).yAxis().labels().format("{%Value}m");
20
21
// set the chart title and padding
22
chart.title('Switching the Series Type in Stock Charts');
23
chart.title().padding(20);
24
25
// create a scroller series with o/h/l/c values
26
var scrollerSeries = chart.scroller().ohlc(table.mapAs({'open':"o",'high': "h", 'low':"l", 'close':"c"}));
27
28
// set the chart container and initiate drawing the chart
29
chart.container(stage);
30
chart.draw();
31
32
// create a label for switching to the OHLC series
33
ohlcLabel = createLabel("Switch to OHLC", 10, function() {
34
// change the series type
35
series.seriesType("ohlc");
36
scrollerSeries.seriesType("ohlc");
37
chart.title("Switching the Series Type in Stock Charts \n OHLC");
38
});
39
40
// create a label for switching to the Japanese candlestick series
41
jcLabel = createLabel("Switch to Japanese Candlestick", 140, function() {
42
// change the series type
43
series.seriesType("candlestick");
44
scrollerSeries.seriesType("candlestick");
45
chart.title("Switching the Series Type in Stock Charts \n Japanese Candlestick");
46
});
47
48
// create label switching to the range area series
49
rangeAreaLabel = createLabel("Switch to Range Area", 375, function() {
50
// change the series type
51
series.seriesType("rangeArea");
52
scrollerSeries.seriesType("rangeArea");
53
chart.title("Switching the Series Type in Stock Charts \n Range Area");
54
});
55
56
});
57
58
// a helper function for creating buttons
59
function createLabel(text, offset, action){
60
var label = anychart.standalones.label();
61
label.background({fill: "#1976d2"});
62
label.text(text);
63
label.fontColor("#fff");
64
label.padding(5);
65
label.parentBounds(offset, 5, 130, 100);
66
label.listen("click", action);
67
label.container(stage);
68
label.draw();
69
label.listen("mouseOver", function(){
70
label.background().fill("#1976d2 0.5")
71
document.body.style.cursor = "pointer";
72
label.draw();
73
});
74
label.listen("mouseOut", function(){
75
label.background().fill("#1976d2")
76
document.body.style.cursor = "auto";
77
label.draw();
78
});
79
return label;
80
}
81
82
// a helper function for setting the data
83
function data_acme_stock (){
84
return[
85
{'x': '2015-04-01', 'o': 18.23, 'h': 19.36, 'l': 18.18, 'c': 19.31},
86
{'x': '2015-04-02', 'o': 19.50, 'h': 19.89, 'l': 19.00, 'c': 19.29},
87
{'x': '2015-04-03', 'o': 19.13, 'h': 19.15, 'l': 18.43, 'c': 18.75},
88
{'x': '2015-04-06', 'o': 18.54, 'h': 18.76, 'l': 18.27, 'c': 18.76},
89
{'x': '2015-04-07', 'o': 18.76, 'h': 19.14, 'l': 18.63, 'c': 18.76},
90
{'x': '2015-04-08', 'o': 18.97, 'h': 19.62, 'l': 18.96, 'c': 19.19},
91
{'x': '2015-04-09', 'o': 19.45, 'h': 19.70, 'l': 19.22, 'c': 19.67},
92
{'x': '2015-04-13', 'o': 19.69, 'h': 19.85, 'l': 19.37, 'c': 19.59},
93
{'x': '2015-04-14', 'o': 19.44, 'h': 19.55, 'l': 19.00, 'c': 19.35},
94
{'x': '2015-04-15', 'o': 19.21, 'h': 19.25, 'l': 18.51, 'c': 18.83},
95
{'x': '2015-04-16', 'o': 19.16, 'h': 19.78, 'l': 18.99, 'c': 19.76},
96
{'x': '2015-04-17', 'o': 19.69, 'h': 19.69, 'l': 19.00, 'c': 19.20},
97
{'x': '2015-04-20', 'o': 18.89, 'h': 18.95, 'l': 18.57, 'c': 18.61},
98
{'x': '2015-04-21', 'o': 18.59, 'h': 19.08, 'l': 18.57, 'c': 18.97},
99
{'x': '2015-04-22', 'o': 18.76, 'h': 19.19, 'l': 18.70, 'c': 18.78},
100
{'x': '2015-04-23', 'o': 18.92, 'h': 18.94, 'l': 18.47, 'c': 18.92},
101
{'x': '2015-04-24', 'o': 19.82, 'h': 21.20, 'l': 19.50, 'c': 20.91},
102
{'x': '2015-04-27', 'o': 20.55, 'h': 20.82, 'l': 20.28, 'c': 20.40},
103
{'x': '2015-04-28', 'o': 20.25, 'h': 20.27, 'l': 19.79, 'c': 19.93},
104
{'x': '2015-04-29', 'o': 20.11, 'h': 20.89, 'l': 20.06, 'c': 20.25},
105
{'x': '2015-04-30', 'o': 20.60, 'h': 21.10, 'l': 20.01, 'c': 20.26},
106
{'x': '2015-05-01', 'o': 20.19, 'h': 20.35, 'l': 19.86, 'c': 20.24},
107
{'x': '2015-05-04', 'o': 20.37, 'h': 20.40, 'l': 19.98, 'c': 20.19},
108
{'x': '2015-05-05', 'o': 20.14, 'h': 20.24, 'l': 19.64, 'c': 19.79},
109
{'x': '2015-05-06', 'o': 20.06, 'h': 20.07, 'l': 19.61, 'c': 19.79},
110
{'x': '2015-05-07', 'o': 19.96, 'h': 19.99, 'l': 19.14, 'c': 19.32},
111
{'x': '2015-05-08', 'o': 19.46, 'h': 19.64, 'l': 19.14, 'c': 19.42},
112
{'x': '2015-05-11', 'o': 19.20, 'h': 19.73, 'l': 19.01, 'c': 19.32},
113
{'x': '2015-05-12', 'o': 19.51, 'h': 20.06, 'l': 19.47, 'c': 19.89},
114
{'x': '2015-05-13', 'o': 19.92, 'h': 20.00, 'l': 19.67, 'c': 19.75},
115
{'x': '2015-05-14', 'o': 19.83, 'h': 20.23, 'l': 19.80, 'c': 20.06},
116
{'x': '2015-05-15', 'o': 20.13, 'h': 20.50, 'l': 19.98, 'c': 20.22},
117
{'x': '2015-05-18', 'o': 20.36, 'h': 20.60, 'l': 20.24, 'c': 20.60},
118
{'x': '2015-05-19', 'o': 20.51, 'h': 20.74, 'l': 20.25, 'c': 20.31},
119
{'x': '2015-05-20', 'o': 20.41, 'h': 20.69, 'l': 20.22, 'c': 20.38},
120
{'x': '2015-05-21', 'o': 20.14, 'h': 20.23, 'l': 19.51, 'c': 19.82},
121
{'x': '2015-05-22', 'o': 19.93, 'h': 20.17, 'l': 19.47, 'c': 19.75},
122
{'x': '2015-05-26', 'o': 19.54, 'h': 20.45, 'l': 19.45, 'c': 20.34},
123
{'x': '2015-05-27', 'o': 20.25, 'h': 20.60, 'l': 20.07, 'c': 20.13},
124
{'x': '2015-05-28', 'o': 20.32, 'h': 20.63, 'l': 20.05, 'c': 20.45},
125
{'x': '2015-05-29', 'o': 20.56, 'h': 20.94, 'l': 20.30, 'c': 20.89},
126
{'x': '2015-06-01', 'o': 21.00, 'h': 21.50, 'l': 20.86, 'c': 21.40},
127
{'x': '2015-06-02', 'o': 21.36, 'h': 21.98, 'l': 21.20, 'c': 21.40},
128
{'x': '2015-06-03', 'o': 21.31, 'h': 21.76, 'l': 21.29, 'c': 21.73},
129
{'x': '2015-06-04', 'o': 21.77, 'h': 21.90, 'l': 21.58, 'c': 21.83},
130
{'x': '2015-06-05', 'o': 21.96, 'h': 22.31, 'l': 21.81, 'c': 22.14},
131
{'x': '2015-06-08', 'o': 21.98, 'h': 22.32, 'l': 21.63, 'c': 22.05},
132
{'x': '2015-06-09', 'o': 22.06, 'h': 22.32, 'l': 21.88, 'c': 22.08},
133
{'x': '2015-06-10', 'o': 22.17, 'h': 22.62, 'l': 22.12, 'c': 22.55},
134
{'x': '2015-06-11', 'o': 22.59, 'h': 23.26, 'l': 22.57, 'c': 22.83},
135
{'x': '2015-06-12', 'o': 22.90, 'h': 23.38, 'l': 22.74, 'c': 23.33},
136
{'x': '2015-06-15', 'o': 23.23, 'h': 23.54, 'l': 23.02, 'c': 23.42},
137
{'x': '2015-06-16', 'o': 23.47, 'h': 24.11, 'l': 23.44, 'c': 23.45},
138
{'x': '2015-06-17', 'o': 23.50, 'h': 23.82, 'l': 23.17, 'c': 23.68},
139
{'x': '2015-06-18', 'o': 23.62, 'h': 23.69, 'l': 23.30, 'c': 23.50},
140
{'x': '2015-06-19', 'o': 24.04, 'h': 24.34, 'l': 23.75, 'c': 24.07},
141
{'x': '2015-06-22', 'o': 23.95, 'h': 23.95, 'l': 23.25, 'c': 23.28},
142
{'x': '2015-06-23', 'o': 23.38, 'h': 23.66, 'l': 23.21, 'c': 23.34},
143
{'x': '2015-06-24', 'o': 23.45, 'h': 23.75, 'l': 23.36, 'c': 23.47},
144
{'x': '2015-06-25', 'o': 23.43, 'h': 23.92, 'l': 23.20, 'c': 23.79},
145
{'x': '2015-06-26', 'o': 23.57, 'h': 23.69, 'l': 23.32, 'c': 23.35},
146
{'x': '2015-06-29', 'o': 23.60, 'h': 24.03, 'l': 23.55, 'c': 23.86},
147
{'x': '2015-06-30', 'o': 23.97, 'h': 24.24, 'l': 23.63, 'c': 23.77},
148
{'x': '2015-07-01', 'o': 24.05, 'h': 24.30, 'l': 23.96, 'c': 24.04},
149
{'x': '2015-07-02', 'o': 23.76, 'h': 24.04, 'l': 23.21, 'c': 23.37}
150
]};