Merge branch 'master' of https://github.com/kberg/dygraphs
[dygraphs.git] / tests / crosshair.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
5 <title>crosshairs</title>
6 <!--[if IE]>
7 <script type="text/javascript" src="../excanvas.js"></script>
8 <![endif]-->
9 <!--
10 For production (minified) code, use:
11 <script type="text/javascript" src="dygraph-combined.js"></script>
12 -->
13 <script type="text/javascript" src="../dygraph-dev.js"></script>
14
15 <script type="text/javascript" src="data.js"></script>
16 </head>
17 <body>
18 <p>Hover, click and zoom to test the callbacks:</p>
19 <div id="div_g" style="width:600px; height:300px; position:relative;">
20 </div>
21
22 <script type="text/javascript">
23 var lines = [];
24 var xline;
25 g = new Dygraph(
26 document.getElementById("div_g"),
27 NoisyData, {
28 rollPeriod: 7,
29 showRoller: true,
30 errorBars: true,
31
32 highlightCallback: function(e, x, pts) {
33 for (var i = 0; i < pts.length; i++) {
34 var y = pts[i].canvasy;
35 lines[i].style.display = "";
36 lines[i].style.top = y + "px";
37 if (i == 0) xline.style.left = pts[i].canvasx + "px";
38 }
39 xline.style.display = "";
40 },
41
42 unhighlightCallback: function(e) {
43 for (var i = 0; i < 2; i++) {
44 lines[i].style.display = "none";
45 }
46 xline.style.display = "none";
47 }
48 }
49 );
50
51 for (var i = 0; i < 2; i++) {
52 var line = document.createElement("div");
53 line.style.display = "none";
54 line.style.width = "100%";
55 line.style.height = "1px";
56 line.style.backgroundColor = "black";
57 line.style.position = "absolute";
58 document.getElementById("div_g").appendChild(line);
59 lines.push(line);
60 }
61
62 xline = document.createElement("div");
63 xline.style.display = "none";
64 xline.style.width = "1px";
65 xline.style.height = "100%";
66 xline.style.top = "0px";
67 xline.style.backgroundColor = "black";
68 xline.style.position = "absolute";
69 document.getElementById("div_g").appendChild(xline);
70 </script>
71 </body>
72 </html>