HTMLcopy
1
<label><input onclick="displayMode('sticky')" type="radio" name="mode" checked>Sticky</label>
2
<label><input onclick="displayMode('float')" type="radio" name="mode">Float</label>
3
<div id="container"></div>
CSScopy
16
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
label {
8
display: inline-block;
9
margin: 10px 0 0 10px;
10
}
11
#container {
12
position: absolute;
13
width: 100%;
14
top: 35px;
15
bottom: 0;
16
}
JavaScriptcopy
x
1
anychart.onDocumentReady(function () {
2
3
// create a data table
4
var dataTable = anychart.data.table();
5
dataTable.addData([
6
['2016-12-24', 19.87],
7
['2016-12-25', 20.08],
8
['2016-12-26', 19.95],
9
['2016-12-27', 20.1],
10
['2016-12-28', 19.91],
11
['2016-12-29', 20.1],
12
['2016-12-30', 19.91],
13
['2016-12-31', 19.36],
14
['2017-01-01', 19.08],
15
['2017-01-02', 19.2],
16
['2017-01-03', 18.99],
17
['2017-01-04', 18.92],
18
['2017-01-05', 18.41],
19
['2017-01-06', 18.57],
20
['2017-01-07', 18.61],
21
['2017-01-08', 19.03],
22
['2017-01-09', 18.91],
23
['2017-01-10', 18.99],
24
['2017-01-11', 18.65]
25
]);
26
27
// map the data
28
mapping = dataTable.mapAs({value: 1});
29
30
// create a stock chart
31
chart = anychart.stock();
32
33
// create a plot and a line series
34
chart.plot(0).line(mapping);
35
36
// set the chart title
37
chart.title("Crosshair: Display Mode = " +
38
chart.crosshair().displayMode());
39
40
// set the container id
41
chart.container("container");
42
43
// initiate drawing the chart
44
chart.draw();
45
});
46
47
// set the display mode of the crosshair
48
function displayMode(mode) {
49
chart.crosshair().displayMode(mode);
50
// update the chart title
51
chart.title("Crosshair: Display Mode = " +
52
chart.crosshair().displayMode());
53
}