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
// The data used in this sample can be obtained from the CDN
3
// https://cdn.anychart.com/csv-data/msft-daily-short.js
4
5
// create data tables on loaded data
6
var msftDataTable = anychart.data.table();
7
msftDataTable.addData(get_msft_daily_short_data()); // eslint-disable-line no-undef
8
9
// create stock chart
10
var chart = anychart.stock();
11
chart.padding(0);
12
chart.tooltip(false);
13
14
// create first plot on the chart
15
var firstPlot = chart.plot(0);
16
17
// get y-scale and set scale ticks settings
18
var yScale = firstPlot.yScale();
19
yScale.ticks().count(10);
20
21
// get y-axis and set labels position and padding
22
var yAxis = firstPlot.yAxis();
23
yAxis.labels().position('inside').padding().left(20);
24
25
// disable drawing of first label and axis line with ticks
26
yAxis.drawFirstLabel(false).stroke(null).ticks().enabled(false);
27
28
// configure plot legend margin
29
firstPlot.legend().margin().bottom(20);
30
31
// get x-axis
32
var xAxis = firstPlot.xAxis();
33
34
// set x-axis labels position and padding
35
xAxis.labels().position('inside').padding().bottom(20);
36
37
// set x-axis minor labels position and padding
38
xAxis.minorLabels().position('inside').padding().bottom(20);
39
40
// set x-axis height
41
xAxis.height(0);
42
43
// disable x-axis helper label
44
xAxis.showHelperLabel(false);
45
46
// set crosshair x-label position and padding
47
firstPlot
48
.crosshair()
49
.xLabel()
50
.enabled(true)
51
.anchor('center-bottom')
52
.padding(4, 15, 4, 20);
53
54
// set crosshair x-label appearance
55
firstPlot
56
.crosshair()
57
.xLabel()
58
.fontColor('#7c868e')
59
.fontSize(11)
60
.background()
61
.fill(anychart.color.lighten('orange'))
62
.stroke('orange');
63
64
firstPlot.crosshair().yStroke(null);
65
66
// set crosshair y-label position and padding
67
firstPlot
68
.crosshair()
69
.yLabel()
70
.anchor('left-center')
71
.padding(4, 15, 4, 20);
72
73
// set crosshair y-label text format and appearance
74
firstPlot
75
.crosshair()
76
.yLabel()
77
.format('{%Value}{decimalsCount:1,zeroFillDecimals:true}')
78
.fontColor('#7c868e')
79
.fontSize(11);
80
81
// set crosshair y-label appearance
82
firstPlot
83
.crosshair()
84
.yLabel()
85
.background()
86
.corners(0, 10, 10, 0)
87
.cornerType('cut')
88
.fill(anychart.color.lighten('orange'))
89
.stroke('orange');
90
91
// get price indicator and set it value
92
var indicator = firstPlot.priceIndicator();
93
indicator.value('last-visible');
94
95
// set price indicator label position and padding
96
indicator.label().anchor('left-center').padding(4, 15, 4, 20);
97
98
// set price indicator text format and color
99
indicator
100
.label()
101
.format('{%Value}{decimalsCount:1,zeroFillDecimals:true}');
102
indicator.label().fontColor('#7c868e');
103
104
// set price indicator appearance
105
indicator
106
.label()
107
.background()
108
.corners(0, 10, 10, 0)
109
.cornerType('cut')
110
.fill(anychart.color.lighten('orange', 0.9))
111
.stroke('orange');
112
indicator.stroke(null);
113
114
// create area series on the first plot
115
var msftSeries = firstPlot.area(msftDataTable.mapAs({ value: 4 }));
116
msftSeries.name('MSFT');
117
msftSeries.color('orange');
118
msftSeries.fill(function () {
119
return anychart.color.setOpacity(this.sourceColor, 0.3, true);
120
});
121
122
msftSeries.hovered().markers().enabled(true);
123
124
chart.scroller(false);
125
126
// set container id for the chart
127
chart.container('container');
128
// initiate chart drawing
129
chart.draw();
130
});