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 data table
4
var dataTable = anychart.data.table();
5
dataTable.addData([
6
["2016-12-24", 511.53, 506.40],
7
["2016-12-25", 512.53, 507.34],
8
["2016-12-26", 511.83, 506.23],
9
["2016-12-27", 511.22, 506.47],
10
["2016-12-28", 510.35, 505.80],
11
["2016-12-29", 510.53, 508.25],
12
["2016-12-30", 511.43, 507.45],
13
["2016-12-31", 511.50, 507.98],
14
["2017-01-01", 511.32, 506.37],
15
["2017-01-02", 511.70, 506.75]
16
]);
17
18
// map the data
19
mapping1 = dataTable.mapAs({value: 1});
20
mapping2 = dataTable.mapAs({value: 2});
21
22
// create a stock chart
23
var chart = anychart.stock();
24
25
// create a plot
26
var plot = chart.plot(0);
27
28
// create two line series
29
plot.line(mapping1);
30
plot.line(mapping2);
31
32
// add a custom legend item
33
plot.legend().itemsFormatter(function(legendItems) {
34
legendItems.push({
35
text: "/ Number of Series: " + plot.getSeriesCount() + " /",
36
iconEnabled: false,
37
fontColor: "#455a64",
38
fontWeight: 600,
39
fontStyle: "italic"
40
});
41
return legendItems;
42
});
43
44
// set the chart title
45
chart.title("AnyStock Legend: Custom Items");
46
47
// set the container id
48
chart.container("container");
49
50
// initiate drawing the chart
51
chart.draw();
52
});