Commit | Line | Data |
---|---|---|
54425b14 | 1 | <!DOCTYPE html> |
d9e6fa47 DV |
2 | <html> |
3 | <head> | |
93a5bb4c | 4 | <link rel="stylesheet" href="../css/dygraph.css"> |
d9e6fa47 | 5 | <title>Highlighted Region</title> |
7e5ddc94 DV |
6 | <!-- |
7 | For production (minified) code, use: | |
8 | <script type="text/javascript" src="dygraph-combined.js"></script> | |
9 | --> | |
fbd6834a | 10 | <script type="text/javascript" src="../dist/dygraph.js"></script> |
7e5ddc94 | 11 | |
d9e6fa47 DV |
12 | <script type="text/javascript" src="data.js"></script> |
13 | </head> | |
14 | <body> | |
15 | <p>Should draw a time series with an unusual region highlighted:</p> | |
16 | <div id="div_g" style="width:600px; height:300px;"></div> | |
17 | ||
18 | <p>When you zoom/pan, the region should remain highlighted.</p> | |
19 | ||
20 | <script type="text/javascript"> | |
21 | // A basic sinusoidal data series. | |
22 | var data = []; | |
23 | for (var i = 0; i < 1000; i++) { | |
24 | var base = 10 * Math.sin(i / 90.0); | |
25 | data.push([i, base, base + Math.sin(i / 2.0)]); | |
26 | } | |
27 | ||
28 | // Shift one portion out of line. | |
29 | var highlight_start = 450; | |
30 | var highlight_end = 500; | |
31 | for (var i = highlight_start; i <= highlight_end; i++) { | |
32 | data[i][2] += 5.0; | |
33 | } | |
34 | ||
35 | ||
f6fbf9e0 | 36 | var g = new Dygraph( |
d9e6fa47 DV |
37 | document.getElementById("div_g"), |
38 | data, | |
39 | { | |
40 | labels: ['X', 'Est.', 'Actual'], | |
b1a3b195 | 41 | animatedZooms: true, |
04143109 | 42 | underlayCallback: function(canvas, area, g) { |
d9e6fa47 DV |
43 | var bottom_left = g.toDomCoords(highlight_start, -20); |
44 | var top_right = g.toDomCoords(highlight_end, +20); | |
45 | ||
46 | var left = bottom_left[0]; | |
47 | var right = top_right[0]; | |
48 | ||
eb7bf005 | 49 | canvas.fillStyle = "rgba(255, 255, 102, 1.0)"; |
d9e6fa47 DV |
50 | canvas.fillRect(left, area.y, right - left, area.h); |
51 | } | |
52 | ||
53 | } | |
54 | ); | |
55 | </script> | |
56 | </body> | |
57 | </html> |