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 that have been used for this sample can be taken from the CDN
3
// https://cdn.anychart.com/csv-data/msft-daily-short.js
4
// https://cdn.anychart.com/csv-data/orcl-daily-short.js
5
6
// create data tables on loaded data
7
var msftDataTable = anychart.data.table();
8
msftDataTable.addData(get_msft_daily_short_data()); // eslint-disable-line no-undef
9
10
var orclDataTable = anychart.data.table();
11
orclDataTable.addData(get_orcl_daily_short_data()); // eslint-disable-line no-undef
12
13
// create stock chart
14
var chart = anychart.stock();
15
16
// create chart title
17
chart.title('Setting-up Scale-Mode (Comparison Modes)');
18
19
// create first plot on the chart with column series
20
var firstPlot = chart.plot(0);
21
// create first plot title
22
firstPlot.legend().titleFormat(function () {
23
return (
24
'<p>Changes comparisonMode="<strong>values</strong>", ' +
25
'compareWith="<strong>2014-06-01</strong>"</p> | ' +
26
anychart.format.dateTime(this.value, 'dd MMM yyyy')
27
);
28
});
29
firstPlot.legend().title().useHtml(true).align('left');
30
// create line series on the first plot
31
firstPlot
32
.line()
33
.name('MSFT')
34
.data(msftDataTable.mapAs({ value: 1 }))
35
.stroke('1 #1976D2');
36
firstPlot
37
.line()
38
.data(orclDataTable.mapAs({ value: 1 }))
39
.stroke('1 #FF5F49')
40
.name('ORCL');
41
// display values
42
firstPlot.yScale().comparisonMode('value');
43
// comparison begins from the timestamp
44
firstPlot.yScale().compareWith('2014-06-01');
45
46
// create second plot on the chart with column series
47
var secondPlot = chart.plot(1);
48
// create second plot title.
49
secondPlot.legend().titleFormat(function () {
50
return (
51
'<p>Changes comparisonMode="<strong>values</strong>", ' +
52
'compareWith="<strong>2015-06-01</strong>"</p> | ' +
53
anychart.format.dateTime(this.value, 'dd MMM yyyy')
54
);
55
});
56
secondPlot.legend().title().useHtml(true).align('center');
57
// create line series on the second plot
58
secondPlot
59
.line()
60
.name('MSFT')
61
.data(msftDataTable.mapAs({ value: 1 }))
62
.stroke('1 #1976D2')
63
.tooltip(false);
64
secondPlot
65
.line()
66
.name('ORCL')
67
.data(orclDataTable.mapAs({ value: 1 }))
68
.stroke('1 #FF5F49')
69
.tooltip(false);
70
// display changes in percents
71
secondPlot.yScale().comparisonMode('value');
72
// comparison begins from the timestamp
73
secondPlot.yScale().compareWith('2015-06-01');
74
75
// create third plot on the chart with column series
76
var thirdPlot = chart.plot(2);
77
// create third plot title
78
thirdPlot.legend().titleFormat(function () {
79
return (
80
'<p>Changes comparisonMode="<strong>percent</strong>", ' +
81
'compareWith="<strong>seriesStart</strong>"</p> | ' +
82
anychart.format.dateTime(this.value, 'dd MMM yyyy')
83
);
84
});
85
thirdPlot.legend().title().useHtml(true).align('left');
86
// create line series on the third plot
87
thirdPlot
88
.line()
89
.name('MSFT')
90
.data(msftDataTable.mapAs({ value: 1 }))
91
.stroke('1 #1976D2')
92
.tooltip(false);
93
thirdPlot
94
.line()
95
.name('ORCL')
96
.data(orclDataTable.mapAs({ value: 1 }))
97
.stroke('1 #FF5F49')
98
.tooltip(false);
99
thirdPlot.yScale().comparisonMode('percent');
100
// comparison begins from the earliest point of all data sets on the chart
101
thirdPlot
102
.yScale()
103
.compareWith('series-start')
104
// force chart to stack values by Y scale.
105
.stackMode('percent');
106
thirdPlot.yAxis().labels().format('{%Value} %'); // percent axis
107
108
// create four plot on the chart with column series
109
var fourthPlot = chart.plot(3);
110
// create four plot title
111
fourthPlot.legend().titleFormat(function () {
112
return (
113
'<p>Changes comparisonMode="<strong>percent</strong>", ' +
114
'compareWith="<strong>firstVisible</strong>"</p> | ' +
115
anychart.format.dateTime(this.value, 'dd MMM yyyy')
116
);
117
});
118
fourthPlot.legend().title().useHtml(true).align('left');
119
// create line series on the third plot
120
fourthPlot
121
.line()
122
.name('MSFT')
123
.data(msftDataTable.mapAs({ value: 1 }))
124
.stroke('1 #1976D2')
125
.tooltip(false);
126
fourthPlot
127
.line()
128
.name('ORCL')
129
.data(orclDataTable.mapAs({ value: 1 }))
130
.stroke('1 #FF5F49')
131
.tooltip(false);
132
fourthPlot
133
.yScale()
134
.comparisonMode('percent')
135
// comparison begins from the earliest point of visible dates
136
.compareWith('first-visible');
137
// force chart to stack values by Y scale.
138
fourthPlot.yScale().stackMode('percent');
139
fourthPlot.yAxis().labels().format('{%Value} %'); // percent axis
140
141
// set chart selected date/time range
142
chart.selectRange('2014-04-30', '2015-10-09');
143
// set container id for the chart
144
chart.container('container');
145
// initiate chart drawing
146
chart.draw();
147
148
// create range picker
149
var rangePicker = anychart.ui.rangePicker();
150
// init range picker
151
rangePicker.render(chart);
152
153
// create range selector
154
var rangeSelector = anychart.ui.rangeSelector();
155
// init range selector
156
rangeSelector.render(chart);
157
});