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 a Fibonacci Time Zones annotation
26
var fibonacciTimezones = controller.fibonacciTimezones({
27
xAnchor: "2004-08-08",
28
valueAnchor: 17.9,
29
secondXAnchor: "2006-10-08",
30
secondValueAnchor: 24.5
31
});
32
33
// configure the annotation labels
34
fibonacciTimezones.labels().format(function() {
35
// convert the level value (timestamp) to a string (date)
36
var levelValue = anychart.format.dateTime(this.levelValue);
37
switch (this.level) {
38
case 0:
39
return this.level + " (" + levelValue + ")";
40
break;
41
default:
42
return this.level;
43
}
44
});
45
46
// set the chart title
47
chart.title("Fibonacci Time Zones: Labels (Formatting Functions)");
48
49
// set the container id
50
chart.container("container");
51
52
// initiate drawing the chart
53
chart.draw();
54
});