HTMLcopy
1
<fieldset>
2
<label for="rangeVal">Baseline:</label>
3
<input type="range" max="1000" min="-1000" oninput="changeBaseline(this.value)" step="1" name="rangeVal" id="rangeVal" value="250">
4
5
<em id="rangeValLabel" style="font-style: normal;"></em>
6
</fieldset>
7
<div id="container"></div>
CSScopy
16
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
fieldset {
8
margin: 10px 0 0 10px;
9
border: 0;
10
}
11
#container {
12
position: absolute;
13
width: 100%;
14
top: 35px;
15
bottom: 0;
16
}
JavaScriptcopy
x
1
var plot;
2
anychart.onDocumentReady(function () {
3
var dataTable = anychart.data.table();
4
dataTable.addData(get_msft_daily_short_data());
5
6
var mapping = dataTable.mapAs({'value': 5});
7
8
var chart = anychart.stock();
9
10
plot = chart.plot();
11
12
// set baseline value
13
plot.baseline(250);
14
15
// create series
16
var series = plot.area(mapping);
17
// configure negative / positive colors
18
series.normal().negativeFill('#EAECC6');
19
series.normal().fill('#2BC0E4');
20
series.normal().negativeStroke('3 #EAECC6');
21
22
// configure markers
23
plot.lineMarker(0).zIndex(1000);
24
plot.lineMarker(0).stroke('2 #fa6b71');
25
plot.textMarker(0).align("left").anchor("right-center").offsetX(5);
26
plot.textMarker(0).fontColor('#fa6b71');
27
28
setMarkers(250);
29
30
chart.title('Custom baseline value');
31
chart.container('container');
32
chart.draw();
33
});
34
35
// function to change baseline on-the-fly
36
function changeBaseline(value){
37
// change baseline
38
plot.baseline(value);
39
// update markers on the plot
40
setMarkers(value);
41
// update label
42
document.getElementById('rangeValLabel').innerHTML = value;
43
}
44
45
// function to set markers value
46
function setMarkers(value){
47
plot.lineMarker(0).value(value);
48
plot.textMarker(0).text(value);
49
plot.textMarker(0).value(value);
50
}
51
52
// function to get data
53
function get_msft_daily_short_data() {
54
return [
55
['2004-01-02', 27.58, 27.77, 27.33, 27.45, 444],
56
['2004-01-05', 27.73, 28.18, 27.72, 28.14, -673],
57
['2004-01-06', 28.19, 28.28, 28.07, 28.24, -469],
58
['2004-01-07', 28.17, 28.31, 28.01, 28.21, -542],
59
['2004-01-08', 28.39, 28.48, 28, 28.16, 588],
60
['2004-01-09', 28.03, 28.06, 27.59, 27.66, 670],
61
['2004-01-12', 27.67, 27.73, 27.35, 27.57, 558],
62
['2004-01-13', 27.55, 27.64, 27.26, 27.43, -515],
63
['2004-01-14', 27.52, 27.73, 27.47, 27.7, -439],
64
['2004-01-15', 27.55, 27.72, 27.42, 27.54, -585],
65
['2004-01-16', 27.71, 27.88, 27.53, 27.81, -639],
66
['2004-01-20', 27.98, 28.2, 27.93, 28.1, 630],
67
['2004-01-21', 28.13, 28.3, 27.85, 28.3, 535],
68
['2004-01-22', 28.36, 28.44, 27.94, 28.01, 784],
69
['2004-01-23', 28.28, 28.76, 28.22, 28.48, -127],
70
['2004-01-24', 28.28, 28.76, 28.22, 28.48, -127],
71
['2004-01-25', 28.28, 28.76, 28.22, 28.48, -127],
72
['2004-01-26', 28.49, 28.83, 28.32, 28.8, -582],
73
['2004-01-27', 28.64, 28.72, 28.22, 28.25, -631],
74
['2004-01-28', 28.3, 28.44, 27.47, 27.71, -713],
75
['2004-01-29', 27.81, 27.95, 27.57, 27.91, -637],
76
['2004-01-30', 27.84, 27.9, 27.55, 27.65, 405],
77
['2004-02-02', 27.61, 27.8, 27.24, 27.4, 628],
78
['2004-02-03', 27.4, 27.55, 27.18, 27.29, -479],
79
['2004-02-04', 27.22, 27.43, 27.01, 27.01, -606],
80
['2004-02-05', 27.06, 27.17, 26.83, 26.96, 555],
81
['2004-02-06', 27.03, 27.19, 26.93, 27.08, 472]
82
];
83
}