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
// create a data table
3
var dataTable = anychart.data.table();
4
dataTable.addData([
5
["2004-01-02", 2011.08, 2022.37, 1999.77, 2006.6801, 1666780032, 2000],
6
["2004-01-05", 2020.78, 2047.36, 2020.78, 2047.36, 2362909952, 1954],
7
["2004-01-06", 2044.55, 2061.54, 2039.63, 2057.3701, 2273220096, 1956],
8
["2004-01-07", 2056.75, 2078.0901, 2047.02, 2077.6799, 2294279936, 1892],
9
["2004-01-08", 2089.6001, 2100.25, 2078.05, 2100.25, 2683950080, 2013],
10
["2004-01-09", 2083.6399, 2113.3301, 2077.0901, 2086.9199, 2482759936, 2109],
11
["2004-01-12", 2093.54, 2112.52, 2085.1499, 2111.78, 2284009984, 2146],
12
["2004-01-13", 2113.1101, 2114.9099, 2080.29, 2096.4399, 2385700096, 2006],
13
["2004-01-14", 2104.29, 2111.73, 2094.3201, 2111.1299, 2099970048, 1793],
14
["2004-01-15", 2101.8601, 2121.6101, 2088.1001, 2109.0801, 2235589888, 1948],
15
["2004-01-16", 2126.1201, 2140.47, 2119.3501, 2140.46, 2614390016, 2094],
16
["2004-01-20", 2149.03, 2149.8501, 2130.2, 2147.98, 2574190080, 2176],
17
["2004-01-21", 2139.3301, 2150.1101, 2120.2, 2142.45, 2421860096, 2012],
18
["2004-01-22", 2146.3201, 2152.1201, 2119.01, 2119.01, 2353370112, 1954],
19
["2004-01-23", 2124.76, 2138.4099, 2108.45, 2123.8701, 2253910016, 1832],
20
["2004-01-26", 2120.5601, 2153.8301, 2115.3401, 2153.8301, 1946050048, 1623],
21
["2004-01-27", 2148.05, 2152.75, 2116.04, 2116.04, 2151259904, 2105],
22
["2004-01-28", 2125.02, 2128, 2073.1499, 2077.3701, 2319549952, 2195],
23
["2004-01-29", 2085.54, 2087.3301, 2041.0699, 2068.23, 2637760000, 2131],
24
["2004-01-30", 2068.3601, 2078.8799, 2058.54, 2066.1499, 1931180032, 2015]
25
]);
26
27
// map the data
28
var mapping = dataTable.mapAs({"value": 4});
29
var ohlcMapping = dataTable.mapAs({"open": 1, "high": 2, "low": 3, "close":4});
30
var lineMapping = dataTable.mapAs({"value": 5});
31
32
// create a stock chart
33
var chart = anychart.stock();
34
chart.padding(0,70,10,50);
35
36
// create a plot on the chart
37
var plot = chart.plot(0);
38
39
// create and configure an additional Y-scale
40
var extraYScale = anychart.scales.linear();
41
extraYScale.minimum(0);
42
extraYScale.maximum(3000000000);
43
var extraTicks = extraYScale.ticks();
44
extraTicks.interval(500000000);
45
46
// create and configure an additional Y-axis
47
var extraYAxis = plot.yAxis(1);
48
extraYAxis.orientation("right");
49
extraYAxis.scale(extraYScale);
50
extraYAxis.labels().format(function(){
51
var value = this.value;
52
return value/1000000 + " mil";
53
});
54
55
// create an OHLC series
56
var ohlcSeries = plot.ohlc(ohlcMapping);
57
ohlcSeries.name("ACME Corp. Stock Prices");
58
59
// create a line series
60
var lineSeries = plot.line(lineMapping);
61
lineSeries.yScale(extraYScale);
62
lineSeries.name("Number of income requests worldwide");
63
64
// an auxiliary variable for working with annotations
65
var controller = plot.annotations();
66
67
// create an Infinite Line annotation (automatically bound to the main Y-scale)
68
controller.infiniteLine({
69
xAnchor: "2004-01-06",
70
valueAnchor: 2039.63,
71
secondXAnchor: "2004-01-15",
72
secondValueAnchor: 2088.10
73
});
74
75
//create an Ellipse annotation
76
var ellipse = controller.ellipse({
77
xAnchor: "2004-01-07",
78
valueAnchor: 2583950080,
79
secondXAnchor: "2004-01-09",
80
secondValueAnchor: 2783950080
81
});
82
83
// bind the Ellipse annotation to the additional Y-scale
84
ellipse.yScale(extraYScale);
85
86
// set the chart title
87
chart.title("Binding Annotations to Axes");
88
89
// set the container id
90
chart.container("container");
91
92
// initiate drawing the chart
93
chart.draw();
94
});