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
var dataTable = anychart.data.table();
3
// data comes from the function in https://cdn.anychart.com/csv-data/dji-daily-short.js
4
dataTable.addData(get_dji_daily_short_data());
5
6
var firstMapping = dataTable.mapAs({value: 1});
7
var secondMapping = dataTable.mapAs({value: 3});
8
9
var chart = anychart.stock();
10
chart.padding(10, 10, 10, 50);
11
12
var nonePlot = chart.plot(0);
13
nonePlot.line(firstMapping);
14
nonePlot.line(secondMapping);
15
nonePlot.legend().titleFormat(function() {return "comparisonMode='none'"});
16
// Set comparison mode to 'none'
17
nonePlot.yScale().comparisonMode("none");
18
19
var valuePlot = chart.plot(1);
20
valuePlot.line(firstMapping);
21
valuePlot.line(secondMapping);
22
valuePlot.legend().titleFormat(function() {return "comparisonMode='value'"});
23
// Set comparison mode 'value'
24
valuePlot.yScale().comparisonMode("value");
25
26
var percentPlot = chart.plot(2);
27
percentPlot.line(firstMapping);
28
percentPlot.line(secondMapping);
29
percentPlot.legend().titleFormat(function() {return "comparisonMode='percent'"});
30
percentPlot.yAxis().labels().format("{%value}%");
31
// Set comparison mode to 'percent'
32
percentPlot.yScale().comparisonMode("percent");
33
34
chart.title("Stock: Different Comparison Modes");
35
chart.container("container");
36
chart.draw();
37
});