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
dataTable.addData(get_dji_daily_short_data());
4
5
var mapping = dataTable.mapAs({value: 1});
6
7
var chart = anychart.stock();
8
9
var indicator = dataTable.createComputer(mapping);
10
indicator.addOutputField('customField', 'uid');
11
indicator.setContext({period: 2000});
12
indicator.setCalculationFunction(function (row) {
13
row.set('customField', row.get('value') + this.period);
14
});
15
16
var indicatorMapping = dataTable.mapAs({value: 'uid'});
17
18
var plot = chart.plot();
19
plot.column(mapping);
20
plot.line(indicatorMapping);
21
plot.getSeries(1).name('Custom indicator');
22
23
// Get field index.
24
var fieldIndex = indicator.getFieldIndex('customField');
25
26
chart.title('Field index: ' + fieldIndex);
27
chart.container('container');
28
chart.draw();
29
});