Commit | Line | Data |
---|---|---|
ce49c2fa DV |
1 | <html> |
2 | <head> | |
3 | <title>demo</title> | |
4 | <!--[if IE]> | |
5 | <script type="text/javascript" src="excanvas.js"></script> | |
6 | <![endif]--> | |
7 | <script type="text/javascript" src="../strftime/strftime-min.js"></script> | |
8 | <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script> | |
9 | <script type="text/javascript" src="../dygraph-canvas.js"></script> | |
10 | <script type="text/javascript" src="../dygraph.js"></script> | |
5c528fa2 DV |
11 | <style type="text/css"> |
12 | .annotation { | |
5c528fa2 DV |
13 | } |
14 | </style> | |
ce49c2fa DV |
15 | </head> |
16 | <body> | |
70aa9072 DV |
17 | <input type="button" value="Add Annotation" onclick="add()" /> |
18 | <div id="events"> </div> | |
5c528fa2 DV |
19 | <div style="position:absolute; left:100px; top: 200px;" id="g"></div> |
20 | <div style="position:absolute; left:600px; top: 200px;" id="list"></div> | |
ce49c2fa DV |
21 | |
22 | <script type="text/javascript"> | |
23 | g = new DateGraph( | |
24 | document.getElementById("g"), | |
25 | function() { | |
26 | var zp = function(x) { if (x < 10) return "0"+x; else return x; }; | |
27 | var r = "date,parabola,line,another line,sine wave\n"; | |
28 | for (var i=1; i<=31; i++) { | |
29 | r += "200610" + zp(i); | |
30 | r += "," + 10*(i*(31-i)); | |
31 | r += "," + 10*(8*i); | |
32 | r += "," + 10*(250 - 8*i); | |
33 | r += "," + 10*(125 + 125 * Math.sin(0.3*i)); | |
34 | r += "\n"; | |
35 | } | |
36 | return r; | |
37 | }, | |
38 | { | |
39 | rollPeriod: 1, | |
5c528fa2 | 40 | showRoller: true, |
ce49c2fa | 41 | width: 480, |
5c528fa2 DV |
42 | height: 320, |
43 | drawCallback: function(g) { | |
44 | var ann = g.annotations(); | |
45 | var html = ""; | |
46 | for (var i = 0; i < ann.length; i++) { | |
47 | html += "(" + ann[i].series + ", " + ann[i].x + "): " + ann[i].shortText + " -> " + ann[i].text + "<br/>"; | |
48 | } | |
49 | document.getElementById("list").innerHTML = html; | |
50 | }, | |
ce49c2fa DV |
51 | } |
52 | ); | |
5c528fa2 DV |
53 | |
54 | var last_ann = 0; | |
55 | annotations = []; | |
56 | for (var x = 10; x < 15; x += 2) { | |
57 | annotations.push( { | |
58 | series: 'sine wave', | |
59 | x: "200610" + x, | |
60 | shortText: x, | |
61 | text: 'Stock Market Crash ' + x | |
62 | } ); | |
63 | last_ann = x; | |
64 | } | |
65 | annotations.push( { | |
66 | series: 'another line', | |
67 | x: "20061013", | |
ce5e8d36 DV |
68 | icon: 'dollar.png', |
69 | iconWidth: 18, | |
70 | iconHeight: 23, | |
71 | tickHeight: 4, | |
5c528fa2 | 72 | text: 'Another one', |
ab5e5c75 DV |
73 | cssClass: 'annotation', |
74 | clickHandler: function() { | |
75 | document.getElementById("events").innerHTML += "special handler<br/>"; | |
76 | } | |
5c528fa2 DV |
77 | } ); |
78 | g.setAnnotations(annotations); | |
79 | ||
80 | function add() { | |
81 | var x = last_ann + 2; | |
82 | var annnotations = g.annotations(); | |
83 | annotations.push( { | |
84 | series: 'line', | |
85 | x: "200610" + x, | |
86 | shortText: x, | |
9a40897e DV |
87 | text: 'Line ' + x, |
88 | tickHeight: 10 | |
5c528fa2 DV |
89 | } ); |
90 | last_ann = x; | |
91 | g.setAnnotations(annotations); | |
92 | } | |
ab5e5c75 | 93 | |
70aa9072 DV |
94 | var eventDiv = document.getElementById("events"); |
95 | function nameAnnotation(ann) { | |
96 | return "(" + ann.series + ", " + ann.x + ")"; | |
97 | } | |
ab5e5c75 DV |
98 | g.updateOptions( { |
99 | annotationClickHandler: function(ann, point, dg, event) { | |
70aa9072 DV |
100 | eventDiv.innerHTML += "click: " + nameAnnotation(ann) + "<br/>"; |
101 | }, | |
102 | annotationDblClickHandler: function(ann, point, dg, event) { | |
103 | eventDiv.innerHTML += "dblclick: " + nameAnnotation(ann) + "<br/>"; | |
104 | }, | |
105 | annotationMouseOverHandler: function(ann, point, dg, event) { | |
106 | eventDiv.innerHTML += "mouseenter: " + nameAnnotation(ann) + "<br/>"; | |
107 | }, | |
108 | annotationMouseOutHandler: function(ann, point, dg, event) { | |
109 | eventDiv.innerHTML += "mouseout: " + nameAnnotation(ann) + "<br/>"; | |
ab5e5c75 DV |
110 | } |
111 | }); | |
ce49c2fa DV |
112 | </script> |
113 | </body> | |
114 | </html> |