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 Trend Channel annotation and configure its visual settings
26
var trendChannel1 = controller.trendChannel({
27
xAnchor: "2007-01-07",
28
valueAnchor: 28.92,
29
secondXAnchor: "2007-09-23",
30
secondValueAnchor: 33.13,
31
thirdXAnchor: "2006-07-30",
32
thirdValueAnchor: 17.24,
33
hovered: {
34
fill: "#398cae 0.3",
35
stroke: "2 #ff0000"
36
},
37
selected: {
38
fill: "#398cae 0.3",
39
hatchFill: "forward-diagonal",
40
stroke: "4 #ff0000"
41
}
42
});
43
44
// create the second Trend Channel annotation
45
var trendChannel2 = controller.trendChannel();
46
47
// set the position of the second annotation
48
trendChannel2.xAnchor("2004-01-11");
49
trendChannel2.valueAnchor(29.13);
50
trendChannel2.secondXAnchor("2005-10-30");
51
trendChannel2.secondValueAnchor(17.87);
52
trendChannel2.thirdXAnchor("2004-08-08");
53
trendChannel2.thirdValueAnchor(17.86);
54
55
// configure the visual settings of the second annotation
56
trendChannel2.normal().fill("none");
57
trendChannel2.normal().stroke("#006600", 1, "10 2");
58
trendChannel2.hovered().stroke("#00b300", 2, "10 2");
59
trendChannel2.selected().stroke("#00b300", 4, "10 2");
60
61
// set the chart title
62
chart.title("Trend Channel: Visual Settings");
63
64
// set the container id
65
chart.container("container");
66
67
// initiate drawing the chart
68
chart.draw();
69
});