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
['2004-01-02', 2011.08, 2022.37, 1999.77, 2006.6801, 1666780032],
7
['2004-01-05', 2020.78, 2047.36, 2020.78, 2047.36, 2362909952],
8
['2004-01-06', 2044.55, 2061.54, 2039.63, 2057.3701, 2273220096],
9
['2004-01-07', 2056.75, 2078.0901, 2047.02, 2077.6799, 2294279936],
10
['2004-01-08', 2089.6001, 2100.25, 2078.05, 2100.25, 2683950080],
11
['2004-01-09', 2083.6399, 2113.3301, 2077.0901, 2086.9199, 2482759936],
12
['2004-01-12', 2093.54, 2112.52, 2085.1499, 2111.78, 2284009984],
13
['2004-01-13', 2113.1101, 2114.9099, 2080.29, 2096.4399, 2385700096],
14
['2004-01-14', 2104.29, 2111.73, 2094.3201, 2111.1299, 2099970048],
15
['2004-01-15', 2101.8601, 2121.6101, 2088.1001, 2109.0801, 2235589888],
16
['2004-01-16', 2126.1201, 2140.47, 2119.3501, 2140.46, 2614390016],
17
['2004-01-20', 2149.03, 2149.8501, 2130.2, 2147.98, 2574190080],
18
['2004-01-21', 2139.3301, 2150.1101, 2120.2, 2142.45, 2421860096],
19
['2004-01-22', 2146.3201, 2152.1201, 2119.01, 2119.01, 2353370112],
20
['2004-01-23', 2124.76, 2138.4099, 2108.45, 2123.8701, 2253910016],
21
['2004-01-26', 2120.5601, 2153.8301, 2115.3401, 2153.8301, 1946050048],
22
['2004-01-27', 2148.05, 2152.75, 2116.04, 2116.04, 2151259904],
23
['2004-01-28', 2125.02, 2128, 2073.1499, 2077.3701, 2319549952],
24
['2004-01-29', 2085.54, 2087.3301, 2041.0699, 2068.23, 2637760000],
25
['2004-01-30', 2068.3601, 2078.8799, 2058.54, 2066.1499, 1931180032]
26
]);
27
28
// map loaded data
29
var mapping = dataTable.mapAs({'value': 2});
30
var ohlcMapping = dataTable.mapAs({'open': 1, 'high': 2, 'low': 3, 'close': 4});
31
var columnMapping = dataTable.mapAs({'value': 3});
32
33
// create stock chart
34
var chart = anychart.stock();
35
36
// create first plot on the chart with column series
37
var firstPlot = chart.plot(0);
38
firstPlot.bounds(0, 0, "45%", "45%");
39
firstPlot.grid(1).enabled(true).layout('vertical');
40
firstPlot.minorGrid().enabled(true);
41
firstPlot.minorGrid(1).enabled(true).layout('vertical');
42
43
44
// create second plot on the chart
45
var secondPlot = chart.plot(1);
46
// turn on second plot grids
47
secondPlot.grid().enabled(true);
48
secondPlot.width("100%");
49
secondPlot.height("45%");
50
secondPlot.top("50%");
51
secondPlot.grid(1).enabled(true).layout('vertical');
52
secondPlot.grid().enabled(true);
53
secondPlot.minorGrid(1).enabled(true).layout('vertical');
54
55
// create third plot
56
var thirdPlot = chart.plot(2);
57
thirdPlot.bounds("55%", 0, "45%", "45%")
58
// turn on third plot grids and minor grids
59
thirdPlot.grid().enabled(true);
60
thirdPlot.grid(1).enabled(true).layout('vertical');
61
thirdPlot.minorGrid().enabled(true);
62
thirdPlot.minorGrid(1).enabled(true).layout('vertical');
63
64
65
// create column series
66
var firstSeries = firstPlot.column(mapping);
67
firstSeries.name("Highest rates");
68
69
// create ohlc series on the second plot
70
var secondSeries = secondPlot.ohlc(ohlcMapping);
71
// set width for columns in percent
72
secondSeries.pointWidth('50%');
73
secondSeries.name("ACME Corp. Stock Prices");
74
75
// create column series on the third plot
76
var thirdSeries = thirdPlot.column(columnMapping);
77
thirdSeries.name("Lowest rates");
78
//set gradient fill for the series
79
thirdSeries.fill("#ef6c00");
80
81
82
// adjust the highlighter of the third plot
83
firstPlot.dateTimeHighlighter("#F44336", 1.5, "6 2", "round");
84
// make the second plot highlighter of green color
85
secondPlot.dateTimeHighlighter({color: "green"});
86
// disable the highlighter on the first plot
87
thirdPlot.dateTimeHighlighter(false);
88
89
// set container id for the chart
90
chart.container('container');
91
92
// initiate chart drawing
93
chart.draw();
94
});