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
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/csv-data/csco-daily.csv
4
anychart.data.loadCsvFile('https://cdn.anychart.com/csv-data/csco-daily.csv', function (data) {
5
// create data table on loaded data
6
var dataTable = anychart.data.table();
7
dataTable.addData(data);
8
9
// map loaded data for the ohlc series
10
var mapping = dataTable.mapAs({'open': 1, 'high': 2, 'low': 3, 'close': 4});
11
12
// create stock chart
13
var chart = anychart.stock();
14
15
// create first plot on the chart
16
var plot = chart.plot(0);
17
// set grid settings
18
plot.yGrid(true)
19
.xGrid(true)
20
.yMinorGrid(true)
21
.xMinorGrid(true);
22
23
var series = plot.candlestick(mapping);
24
series.name('CSCO');
25
series.legendItem().iconType('rising-falling');
26
27
28
//create annotations
29
30
// create a plot on the chart
31
var plot = chart.plot(0);
32
33
// access the annotations() object of the plot to work with annotations
34
var controller = plot.annotations();
35
36
// create a Label annotation
37
controller.label({
38
xAnchor: '2008-12-14',
39
valueAnchor: 25,
40
text: "Target",
41
background: {
42
fill: 'white',
43
stroke: 'none'
44
},
45
fontColor: 'green'
46
});
47
48
//create horizontal line annotations
49
controller.horizontalLine({
50
valueAnchor: 15
51
});
52
53
controller.horizontalLine({
54
valueAnchor: 25,
55
stroke: {
56
color: 'green',
57
thickness: 2,
58
dash: '10 2'
59
}
60
});
61
62
//create line segments
63
controller.line({
64
xAnchor: "2007-09-02",
65
valueAnchor: 37,
66
secondXAnchor: "2008-03-30",
67
secondValueAnchor: 13,
68
stroke: {
69
color: 'green',
70
thickness: 2,
71
dash: '10 2'
72
}
73
});
74
75
controller.line({
76
xAnchor: "2008-03-30",
77
valueAnchor: 13,
78
secondXAnchor: "2009-01-04",
79
secondValueAnchor: 28,
80
stroke: {
81
color: 'blue',
82
thickness: 3,
83
dash: '3 5'
84
}
85
});
86
87
//create range markers
88
var xAxis = chart.plot(0).xAxis();
89
// create range marker
90
chart.plot(0).rangeMarker(0)
91
.from('2008-07-07')
92
.to('2009-01-04')
93
// set marker inner color
94
.fill("#ffbac8 0.3")
95
// set axis
96
.axis(xAxis);
97
98
// create range marker
99
chart.plot(0).rangeMarker(1)
100
.from('2006-07-06')
101
.to('2008-07-06')
102
// set marker inner color
103
.fill("#5af790 0.3")
104
// set axis
105
.axis(xAxis);
106
107
108
chart.plot(0).rangeMarker(2)
109
.from('2009-01-05')
110
.to('2009-06-28')
111
// set marker inner color
112
.fill("#d3d3d3 0.3")
113
// set axis
114
.axis(xAxis);
115
116
var grouping = chart.grouping();
117
// set the max number of points
118
grouping.maxVisiblePoints(500);
119
120
// set container id for the chart and render
121
chart.container('container').draw();
122
// set chart selected date/time range
123
chart.selectRange('points', 500, 'last-date', true);
124
});
125
});