4 <meta http-equiv=
"X-UA-Compatible" content=
"IE=EmulateIE7; IE=EmulateIE9">
7 <script type=
"text/javascript" src=
"../excanvas.js"></script>
10 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
12 <script type=
"text/javascript" src=
"../strftime/strftime-min.js"></script>
13 <script type=
"text/javascript" src=
"../rgbcolor/rgbcolor.js"></script>
14 <script type=
"text/javascript" src=
"../dygraph-canvas.js"></script>
15 <script type=
"text/javascript" src=
"../dygraph.js"></script>
16 <style type=
"text/css">
22 <h3>Annotations Demo
</h3>
23 <p>Click any point to add an annotation to it or click
"Add Annotation".
</p>
24 <input type=
"button" value=
"Add Annotation" onclick=
"add()" />
25 <input type=
"button" value=
"Shove to bottom" onclick=
"bottom(this)" />
26 <div id=
"events"> </div>
27 <div style=
"position:absolute; left:200px; top: 200px;" id=
"g_div"></div>
28 <div style=
"position:absolute; left:700px; top: 200px;" id=
"list"></div>
30 <script type=
"text/javascript">
31 var eventDiv = document.getElementById(
"events");
32 function nameAnnotation(ann) {
33 return
"(" + ann.series +
", " + ann.x +
")";
37 document.getElementById(
"g_div"),
39 var zp = function(x) { if (x <
10) return
"0"+x; else return x; };
40 var r =
"date,parabola,line,another line,sine wave\n";
41 for (var i=
1; i<=
31; i++) {
42 r +=
"200610" + zp(i);
43 r +=
"," +
10*(i*(
31-i));
45 r +=
"," +
10*(
250 -
8*i);
46 r +=
"," +
10*(
125 +
125 * Math.sin(
0.3*i));
56 drawCallback: function(g) {
57 var ann = g.annotations();
59 for (var i =
0; i < ann.length; i++) {
60 var name = nameAnnotation(ann[i]);
61 html +=
"<span id='" + name +
"'>"
62 html += name +
": " + (ann[i].shortText || '(icon)')
63 html +=
" -> " + ann[i].text +
"</span><br/>";
65 document.getElementById(
"list").innerHTML = html;
72 for (var x =
10; x <
15; x +=
2) {
77 text: 'Stock Market Crash ' + x
82 series: 'another line',
89 cssClass: 'annotation',
90 clickHandler: function() {
91 document.getElementById(
"events").innerHTML +=
"special handler<br/>";
94 g.setAnnotations(annotations);
98 var annnotations = g.annotations();
107 g.setAnnotations(annotations);
110 function bottom(el) {
111 var to_bottom = true;
112 if (el.value != 'Shove to bottom') to_bottom = false;
114 var anns = g.annotations();
115 for (var i =
0; i < anns.length; i++) {
116 anns[i].attachAtBottom = to_bottom;
118 g.setAnnotations(anns);
121 el.value = 'Lift back up';
123 el.value = 'Shove to bottom';
130 annotationClickHandler: function(ann, point, dg, event) {
131 eventDiv.innerHTML +=
"click: " + nameAnnotation(ann) +
"<br/>";
133 annotationDblClickHandler: function(ann, point, dg, event) {
134 eventDiv.innerHTML +=
"dblclick: " + nameAnnotation(ann) +
"<br/>";
136 annotationMouseOverHandler: function(ann, point, dg, event) {
137 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
138 saveBg = ann.div.style.backgroundColor;
139 ann.div.style.backgroundColor = '#ddd';
141 annotationMouseOutHandler: function(ann, point, dg, event) {
142 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
143 ann.div.style.backgroundColor = saveBg;
146 pointClickCallback: function(event, p) {
147 // Check if the point is already annotated.
148 if (p.annotation) return;
155 text:
"Annotation #" + num
157 var anns = g.annotations();
159 g.setAnnotations(anns);