HTMLcopy
1
<button onclick="crosshairEnabled(false)">Disable</button>
2
<button onclick="crosshairEnabled(true)">Enable</button>
3
<div id="container"></div>
CSScopy
15
1
html, body {
2
width: 100%;
3
height: 100%;
4
margin: 0;
5
padding: 0;
6
}
7
button {
8
margin: 10px 0 0 10px;
9
}
10
#container {
11
position: absolute;
12
width: 100%;
13
top: 35px;
14
bottom: 0;
15
}
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: Enabled = " + chart.crosshair().enabled());
38
39
// set the container id
40
chart.container("container");
41
42
// initiate drawing the chart
43
chart.draw();
44
});
45
46
// enable / disable the crosshair
47
function crosshairEnabled(enabled) {
48
chart.crosshair(enabled);
49
// update the chart title
50
chart.title("Crosshair: Enabling = " + chart.crosshair().enabled());
51
}