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
var dataTable = anychart.data.table();
3
4
// The data used in this sample can be obtained from the CDN
5
// https://cdn.anychart.com/csv-data/dji-daily-short.js
6
dataTable.addData(get_dji_daily_short_data());
7
8
var mapping = dataTable.mapAs({open: 1, high: 2, low: 3, close: 4, volume: 4});
9
10
var chart = anychart.stock();
11
12
// Create computer.
13
var computer = dataTable.createComputer(mapping);
14
15
var context = anychart.math.momentum.initContext(30);
16
17
// Set init context.
18
computer.setContext(context);
19
20
// Set start calculation function.
21
computer.setStartFunction(anychart.math.momentum.startFunction);
22
23
// Calculation function.
24
computer.setCalculationFunction(anychart.math.momentum.calculationFunction);
25
26
var indicatorMapping = dataTable.mapAs({value: computer.addOutputField('result')});
27
28
var plot = chart.plot();
29
plot.line(indicatorMapping).name('Momentum(20)');
30
31
chart.container('container');
32
chart.draw();
33
});