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