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
// The data used in this sample can be obtained from the CDN
2
// https://cdn.anychart.com/csv-data/aapl-daily.csv
3
anychart.data.loadCsvFile('https://cdn.anychart.com/csv-data/aapl-daily.csv', function (data) {
4
// create data table on loaded data
5
var dataTable = anychart.data.table();
6
dataTable.addData(data);
7
8
// map loaded data
9
var mapping = dataTable.mapAs({
10
open: 1,
11
high: 2,
12
low: 3,
13
close: 4,
14
value: {
15
column: 6,
16
type: 'sum'
17
}
18
});
19
20
// create stock chart
21
var chart = anychart.stock(true);
22
// set chart padding
23
chart.padding().right(60);
24
25
// create plot on the chart
26
var plot = chart.plot(0);
27
// enabled x-grid/y-grid
28
plot.xGrid(true)
29
.yGrid(true);
30
31
// set orientation y-axis to the right side
32
plot.yAxis().orientation('right');
33
34
// create custom palette
35
var palette = anychart.palettes.distinctColors();
36
palette.items(['red', 'green']);
37
38
// create candlestick series on the plot
39
var aaplSeries = plot.candlestick(mapping);
40
// set series settings
41
aaplSeries.name('AAPL')
42
.zIndex(50);
43
aaplSeries.risingFill(palette.itemAt(0), 0.5)
44
.fallingFill(palette.itemAt(1), 0.5)
45
.risingStroke(palette.itemAt(0), 0.5)
46
.fallingStroke(palette.itemAt(1), 0.5);
47
48
// create volume series on the plot
49
var volumeSeries = plot.column(mapping);
50
// set series settings
51
volumeSeries.name('Volume')
52
.zIndex(100)
53
.maxHeight('20%')
54
.bottom(0);
55
56
// create a logarithmic scale
57
var customScale = anychart.scales.log();
58
// sets y-scale
59
volumeSeries.yScale(customScale);
60
61
// set volume fill settings
62
volumeSeries.risingFill(palette.itemAt(0), 0.25)
63
.fallingFill(palette.itemAt(1), 0.25)
64
.risingStroke(palette.itemAt(0), 0.25)
65
.fallingStroke(palette.itemAt(1), 0.25);
66
67
volumeSeries.fill(function() {
68
if(this.iterator.get('open') < this.iterator.get('close')) {
69
return palette.itemAt(0) + ' 0.4';
70
} else {
71
return palette.itemAt(1) + ' 0.4';
72
}
73
});
74
75
volumeSeries.stroke(function() {
76
if(this.iterator.get('open') < this.iterator.get('close')) {
77
return palette.itemAt(0) + ' 0.4';
78
} else {
79
return palette.itemAt(1) + ' 0.4';
80
}
81
});
82
83
// set container id for the chart
84
chart.container('container').draw()
85
});