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
var stage = anychart.graphics.create("container");
5
6
// create a data table
7
var dataTable = anychart.data.table();
8
dataTable.addData([
9
["2016-12-24", 511.53, 514.98, 505.79, 506.40],
10
["2016-12-25", 512.53, 514.88, 505.69, 507.34],
11
["2016-12-26", 511.83, 514.98, 505.59, 506.23],
12
["2016-12-27", 511.22, 515.30, 505.49, 506.47],
13
["2016-12-28", 510.35, 515.72, 505.23, 505.80],
14
["2016-12-29", 510.53, 515.86, 505.38, 508.25],
15
["2016-12-30", 511.43, 515.98, 505.66, 507.45],
16
["2016-12-31", 511.50, 515.33, 505.99, 507.98],
17
["2017-01-01", 511.32, 514.29, 505.99, 506.37],
18
["2017-01-02", 511.70, 514.87, 506.18, 506.75]
19
]);
20
21
// map the data
22
mapping = dataTable.mapAs(
23
{open: 1, high: 2, low: 3, close: 4, value: 4}
24
);
25
26
// create a stock chart
27
var chart = anychart.stock();
28
29
// create two plots
30
var plot1 = chart.plot(0);
31
var plot2 = chart.plot(1);
32
33
// create two series: line and ohlc
34
plot1.line(mapping);
35
plot2.ohlc(mapping);
36
37
// disable the legend on both plots
38
plot1.legend(false);
39
plot2.legend(false);
40
41
/* set the position of the chart to prevent
42
the standalone legend from overlapping it */
43
chart.top(25);
44
45
// set the chart title
46
chart.title("Standalone Legend in AnyStock")
47
48
// set the chart container
49
chart.container(stage);
50
51
// initiate drawing the chart
52
chart.draw();
53
54
// create a standalone legend
55
var legend = anychart.standalones.legend();
56
57
// set the source of legend items
58
legend.itemsSource([plot1, plot2]);
59
60
// set the padding of the legend
61
legend.padding(10);
62
63
// set the container for the legend
64
legend.container(stage);
65
66
// draw the legend
67
legend.draw();
68
});