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 data table on loaded data
4
var dataTable = anychart.data.table();
5
dataTable.addData([
6
['2014-01-02', 2011.08, 2022.37, 1999.77, 2006.6801, 1666780032],
7
['2014-01-05', 2020.78, 2047.36, 2020.78, 2047.36, 2362909952],
8
['2014-01-06', 2044.55, 2061.54, 2039.63, 2057.3701, 2273220096],
9
['2014-01-07', 2056.75, 2078.0901, 2047.02, 2077.6799, 2294279936],
10
['2014-01-08', 2089.6001, 2100.25, 2078.05, 2100.25, 2683950080],
11
['2014-01-09', 2083.6399, 2113.3301, 2077.0901, 2086.9199, 2482759936],
12
['2014-01-12', 2093.54, 2112.52, 2085.1499, 2111.78, 2284009984],
13
['2014-01-13', 2113.1101, 2114.9099, 2080.29, 2096.4399, 2385700096],
14
['2014-01-14', 2104.29, 2111.73, 2094.3201, 2111.1299, 2099970048],
15
['2014-01-15', 2101.8601, 2121.6101, 2088.1001, 2109.0801, 2235589888],
16
['2014-01-16', 2126.1201, 2140.47, 2119.3501, 2140.46, 2614390016],
17
['2014-01-20', 2149.03, 2149.8501, 2130.2, 2147.98, 2574190080],
18
['2014-01-21', 2139.3301, 2150.1101, 2120.2, 2142.45, 2421860096],
19
['2014-01-22', 2146.3201, 2152.1201, 2119.01, 2119.01, 2353370112],
20
['2014-01-23', 2124.76, 2138.4099, 2108.45, 2123.8701, 2253910016],
21
['2014-01-26', 2120.5601, 2153.8301, 2115.3401, 2153.8301, 1946050048],
22
['2014-01-27', 2148.05, 2152.75, 2116.04, 2116.04, 2151259904],
23
['2014-01-28', 2125.02, 2128, 2073.1499, 2077.3701, 2319549952],
24
['2014-01-29', 2085.54, 2087.3301, 2041.0699, 2068.23, 2637760000],
25
['2014-01-30', 2068.3601, 2078.8799, 2058.54, 2066.1499, 1931180032],
26
['2014-01-31', 2020.78, 2047.36, 2020.78, 2047.36, 2362909952],
27
['2014-02-01', 2044.55, 2061.54, 2039.63, 2057.3701, 2273220096],
28
['2014-02-02', 2056.75, 2078.0901, 2047.02, 2077.6799, 2294279936],
29
['2014-02-03', 2089.6001, 2100.25, 2078.05, 2100.25, 2683950080],
30
['2014-02-04', 2083.6399, 2113.3301, 2077.0901, 2086.9199, 2482759936],
31
['2014-02-05', 2093.54, 2112.52, 2085.1499, 2111.78, 2284009984],
32
['2014-02-06', 2113.1101, 2114.9099, 2080.29, 2096.4399, 2385700096],
33
['2014-02-07', 2104.29, 2111.73, 2094.3201, 2111.1299, 2099970048],
34
['2014-02-08', 2101.8601, 2121.6101, 2088.1001, 2109.0801, 2235589888],
35
['2014-02-09', 2126.1201, 2140.47, 2119.3501, 2140.46, 2614390016],
36
['2014-02-10', 2149.03, 2149.8501, 2130.2, 2147.98, 2574190080],
37
['2014-02-11', 2139.3301, 2150.1101, 2120.2, 2142.45, 2421860096],
38
['2014-02-12', 2146.3201, 2152.1201, 2119.01, 2119.01, 2353370112],
39
['2014-02-13', 2124.76, 2138.4099, 2108.45, 2123.8701, 2253910016],
40
['2014-02-16', 2120.5601, 2153.8301, 2115.3401, 2153.8301, 1946050048],
41
['2014-02-17', 2148.05, 2152.75, 2116.04, 2116.04, 2151259904],
42
['2014-02-18', 2125.02, 2128, 2073.1499, 2077.3701, 2319549952],
43
['2014-02-19', 2085.54, 2087.3301, 2041.0699, 2068.23, 2637760000],
44
['2014-02-20', 2149.03, 2149.8501, 2130.2, 2147.98, 2574190080],
45
['2014-02-21', 2139.3301, 2150.1101, 2120.2, 2142.45, 2421860096],
46
['2014-02-22', 2146.3201, 2152.1201, 2119.01, 2119.01, 2353370112],
47
['2014-02-23', 2124.76, 2138.4099, 2108.45, 2123.8701, 2253910016],
48
['2014-02-26', 2120.5601, 2153.8301, 2115.3401, 2153.8301, 1946050048],
49
['2014-02-27', 2148.05, 2152.75, 2116.04, 2116.04, 2151259904],
50
['2014-02-28', 2125.02, 2128, 2073.1499, 2077.3701, 2319549952]
51
]);
52
53
// map loaded data
54
var ohlc_mapping = dataTable.mapAs({'open': 1, 'high': 2, 'low': 3, 'close': 4, 'volume': 5});
55
var line_high_mapping = dataTable.mapAs({'value': 2});
56
var line_close_mapping = dataTable.mapAs({'value': 4});
57
58
// create stock chart
59
var chart = anychart.stock();
60
61
// create first plot on the chart with column series
62
var plot = chart.plot(0);
63
var series = plot.ohlc(ohlc_mapping);
64
var line_high_series = plot.line(line_high_mapping);
65
var line_close_series = plot.line(line_close_mapping);
66
67
// colors
68
series.fallingStroke("#bbb");
69
series.risingStroke("#888");
70
line_high_series.stroke("#FF6D00");
71
line_close_series.stroke("#1565C0");
72
73
series.name("OHLC");
74
line_high_series.name("High values of the ACME Sales");
75
line_close_series.name("Close values of the ACME Sales");
76
77
var legend = plot.legend();
78
// enables legend
79
legend.enabled(true);
80
81
// turn the title on and set the position
82
legend.title(false);
83
84
// add a background
85
legend.background("#E1F5FE");
86
87
// change size in height
88
legend.height(35);
89
90
// adjust the paginator
91
legend.paginator(true);
92
legend.paginator().orientation("right");
93
94
// icons
95
var item = series.legendItem();
96
var item_h = line_high_series.legendItem();
97
var item_c = line_close_series.legendItem();
98
// set stroke of icons
99
item.iconStroke("#000")
100
item_h.iconStroke("#FF6D00");
101
item_c.iconStroke("#1565C0");
102
// set type of icon marker
103
item.iconType("ohlc");
104
item_h.iconType("line");
105
item_c.iconType("line");
106
107
// set legend position and items layout
108
legend.itemsLayout('horizontal');
109
legend.position('top');
110
legend.itemsFormat(function(){
111
if (this.open !== undefined){
112
return "Open: " + this.open+ " High: " + this.high+ " Low: " + this.low+ " Close: " + this.close
113
}
114
});
115
116
// setting the space between the items
117
legend.itemsSpacing(10);
118
119
// enable the scroller
120
chart.scroller().enabled(true);
121
122
// adjust the scroller
123
chart.selectRange('2014-01-02','2014-02-03');
124
125
// set container id for the chart
126
chart.container('container');
127
128
// adjust the scroller axis
129
var labels = chart.scroller().xAxis().labels();
130
var minorLabels = chart.scroller().xAxis().minorLabels();
131
132
133
// initiate chart drawing
134
chart.draw();
135
});