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 that used in this sample obtained from the CDN
3
// https://cdn.anychart.com/csv-data/csco-daily.js
4
5
// create data table on loaded data
6
var dataTable = anychart.data.table();
7
dataTable.addData(get_csco_daily_data());
8
9
// map loaded data
10
var mapping = dataTable.mapAs({'value': 4});
11
12
// create stock chart
13
var chart = anychart.stock();
14
15
// create plot on the chart
16
var plot = chart.plot(0);
17
18
// create line series
19
var lineSeries = plot.line(mapping);
20
lineSeries.name('CSCO');
21
lineSeries.stroke('2px #64b5f6');
22
23
// create computer
24
var computer = dataTable.createComputer(mapping);
25
26
// set computer output field
27
computer.addOutputField('myValue', 'myColumn');
28
29
// set calculation function to produce values with random increment
30
computer.setCalculationFunction(function(row) {
31
var value = row.get('value');
32
var myValue = value + Math.floor((Math.random() * 100) + 1);
33
row.set('myValue', myValue);
34
});
35
36
// map computed column 'myColumn' as value
37
var computedMapping = dataTable.mapAs({'value': 'myColumn'});
38
39
// create line series with mapping
40
var computedLine = plot.line(computedMapping);
41
computedLine.name('Custom Indicator');
42
computedLine.stroke('#ffa000 0.6');
43
44
// set Y Axis settings
45
var yAxis = plot.yAxis();
46
yAxis.orientation('right');
47
48
// create scroller series with mapped data
49
chart.scroller().line(mapping);
50
51
// set container id for the chart
52
chart.container('container');
53
54
// initiate chart drawing
55
chart.draw();
56
});