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.js
4
var dataTable = anychart.data.table();
5
dataTable.addData(get_csco_daily_data());
6
7
var mapping = dataTable.mapAs({
8
'open': 1,
9
'high': 2,
10
'low': 3,
11
'close': 4,
12
'value': {column: 4, type: 'close'}
13
});
14
15
var chart = anychart.stock();
16
17
// Create computer.
18
var computer = dataTable.createComputer(mapping);
19
20
// Set init context using preset bbands context.
21
computer.setContext(anychart.math.bbands.initContext(30, 5));
22
23
// Set start function using preset bbands start function.
24
computer.setStartFunction(anychart.math.bbands.startFunction);
25
26
// Set calculation function using preset bbands calculation function.
27
computer.setCalculationFunction(anychart.math.bbands.calculationFunction);
28
29
// Define output fields
30
computer.addOutputField('upperResult');
31
computer.addOutputField('lowerResult');
32
33
// Add a range spline series using the data from the computer
34
bbandsSeries = chart.plot().rangeSplineArea(dataTable, {high: computer.getFieldIndex('upperResult'), low: computer.getFieldIndex('lowerResult')});
35
36
// Set name and visual effects
37
bbandsSeries.name("BBands");
38
bbandsSeries.fill({color: "Gray", opacity: 0.1});
39
bbandsSeries.highStroke("Red 0.5", 2, "2 2");
40
bbandsSeries.lowStroke("Blue 0.5", 2, "2 2");
41
42
// add OHLC series
43
ohlcSeries = chart.plot().ohlc(mapping);
44
ohlcSeries.name("ACME");
45
46
chart.container("container");
47
chart.draw();
48
});