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
// the data used in this sample can be obtained from the CDN
4
// https://cdn.anychart.com/csv-data/csco-daily.js
5
// create a data table using this data
6
var dataTable = anychart.data.table();
7
dataTable.addData(get_csco_daily_short_data());
8
9
// map the data
10
var mapping = dataTable.mapAs({"value": 4});
11
12
// create a stock chart
13
var chart = anychart.stock();
14
15
// create a plot on the chart
16
var plot = chart.plot(0);
17
18
// create a line series
19
var lineSeries = plot.line(mapping);
20
lineSeries.name("CSCO");
21
22
// access the annotations() object of the plot to work with annotations
23
var controller = plot.annotations();
24
25
// create the first Label annotation and configure its size, offset and visual settings
26
var label1 = controller.label({
27
xAnchor: "2006-07-30",
28
valueAnchor: 17.24,
29
text: "Buy",
30
normal: {fontColor: "#008000", fontSize: 20},
31
hovered: {fontColor: "#00e600", fontSize: 23},
32
selected: {fontColor: "#00e600", fontSize: 23}
33
});
34
35
// create the second Label annotation
36
var label2 = controller.label();
37
38
// set the position of the second annotation
39
label2.xAnchor("2007-10-28");
40
label2.valueAnchor(32.51);
41
42
// set the text of the second annotation
43
label2.text("Sell");
44
45
// configure the visual settings of the second annotation
46
label2.normal().fontColor("#800000");
47
label2.normal().fontSize(40);
48
label2.hovered().fontColor("#e60000");
49
label2.hovered().fontSize(43);
50
label2.selected().fontColor("#e60000");
51
label2.selected().fontSize(43);
52
53
// set the chart title
54
chart.title("Label: Appearance");
55
56
// set the container id
57
chart.container("container");
58
59
// initiate drawing the chart
60
chart.draw();
61
});