HTMLcopy
1
<div id="container"></div>
CSScopy
8
1
html,
2
body,
3
#container {
4
width: 100%;
5
height: 100%;
6
margin: 0;
7
padding: 0;
8
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
// get data from https://cdn.anychart.com/solutions-data/acme-corp-price/data.js
3
var data = acme_corp_data(); // eslint-disable-line no-undef
4
// create stage
5
var stage = anychart.graphics.create('container');
6
// create data set on loaded data
7
var dataSet = anychart.data.set(data);
8
9
// map data for the range spline area series
10
var firstSeriesData = dataSet.mapAs({ x: 0, low: 1, high: 2 });
11
// map data for the candlestick series
12
var secondSeriesData = dataSet.mapAs({
13
x: 0,
14
open: 3,
15
high: 4,
16
low: 5,
17
close: 6
18
});
19
// map data for the spline series
20
var thirdSeriesData = dataSet.mapAs({ x: 0, value: 7 });
21
22
// create chart
23
var chartFirst = anychart.area();
24
// set title
25
chartFirst.title('ACME Corp. Stock Prices: 11.05.07 - 07.08.07');
26
// set position for the first stage
27
chartFirst.bounds(0, 0, '100%', '70%');
28
// create range spline area series
29
chartFirst.rangeSplineArea(firstSeriesData).name('Range Spline Area');
30
// create candlestick series
31
chartFirst.candlestick(secondSeriesData).name('Candlestick');
32
// create spline series
33
chartFirst.spline(thirdSeriesData).markers(null).name('Spline');
34
35
// set xScale settings
36
var xScale = chartFirst.xScale();
37
xScale.inverted(true);
38
39
// set xTicks settings
40
xScale.ticks().interval(7);
41
42
// set xAxis settings
43
chartFirst
44
.xAxis()
45
.drawFirstLabel(false)
46
.labels()
47
.format(function () {
48
var options = { year: 'numeric', month: 'long', day: 'numeric' };
49
return new Date(this.value).toLocaleDateString('en-US', options);
50
});
51
52
// set tooltip settings
53
chartFirst
54
.tooltip()
55
.displayMode('union')
56
.titleFormat(function () {
57
return anychart.format.dateTime(
58
this.points[0].x,
59
'dd/MM/yyyy',
60
null,
61
null
62
);
63
})
64
.unionFormat(function () {
65
return (
66
this.points[0].seriesName +
67
'\nHigh: ' +
68
this.points[0].high.toFixed(2) +
69
'\nLow: ' +
70
this.points[0].low.toFixed(2) +
71
'\n\n' +
72
this.points[1].seriesName +
73
'\nOpen: ' +
74
this.points[1].open +
75
'\nHigh: ' +
76
this.points[1].high +
77
'\nLow: ' +
78
this.points[1].low +
79
'\nClose: ' +
80
this.points[1].close +
81
'\n\n' +
82
this.points[2].seriesName +
83
'\nValue: ' +
84
this.points[2].value.toFixed(2)
85
);
86
});
87
// set stage for the chart
88
chartFirst.container(stage);
89
// initiate chart drawing
90
chartFirst.draw();
91
92
// map data for the column series
93
var columnData = dataSet.mapAs({ x: 0, value: 8 });
94
95
// create column chart
96
var chartSecond = anychart.column(columnData);
97
chartSecond
98
.bounds(0, '70%', '100%', '30%')
99
.interactivity()
100
.hoverMode('by-x');
101
102
chartSecond
103
.tooltip()
104
.titleFormat(function () {
105
return anychart.format.dateTime(this.x, 'dd/MM/yyyy', null, null);
106
})
107
.format('${%Value}{groupsSeparator: } stocks bought');
108
109
chartSecond.getSeries(0).hovered().fill('orange').stroke('#EF6C00');
110
111
chartSecond.xScale().inverted(true);
112
113
// adjust axes labels view
114
chartSecond.xAxis().labels(false);
115
116
chartSecond
117
.yAxis()
118
.labels()
119
.format('${%Value}{scale:(1000000)(1)|( mln)}');
120
121
// adjust x axis internal
122
chartSecond.xScale().ticks().interval(11);
123
// set stage for the chart
124
chartSecond.container(stage);
125
// initiate chart drawing
126
chartSecond.draw();
127
});