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>
13 For production (minified) code, use:
14 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
16 <script type=
"text/javascript" src=
"../dygraph-dev.js"></script>
18 <style type=
"text/css">
24 <h3>Annotations Demo
</h3>
25 <p>Click any point to add an annotation to it or click
"Add Annotation".
</p>
26 <input type=
"button" value=
"Add Annotation" onclick=
"add()" />
27 <input type=
"button" value=
"Shove to bottom" onclick=
"bottom(this)" />
28 <div id=
"events"> </div>
29 <div style=
"position:absolute; left:200px; top: 200px;" id=
"g_div"></div>
30 <div style=
"position:absolute; left:700px; top: 200px;" id=
"list"></div>
32 <script type=
"text/javascript">
33 var eventDiv = document.getElementById(
"events");
34 function nameAnnotation(ann) {
35 return
"(" + ann.series +
", " + ann.x +
")";
39 document.getElementById(
"g_div"),
41 var zp = function(x) { if (x <
10) return
"0"+x; else return x; };
42 var r =
"date,parabola,line,another line,sine wave\n";
43 for (var i=
1; i<=
31; i++) {
44 r +=
"200610" + zp(i);
45 r +=
"," +
10*(i*(
31-i));
47 r +=
"," +
10*(
250 -
8*i);
48 r +=
"," +
10*(
125 +
125 * Math.sin(
0.3*i));
58 drawCallback: function(g) {
59 var ann = g.annotations();
61 for (var i =
0; i < ann.length; i++) {
62 var name = nameAnnotation(ann[i]);
63 html +=
"<span id='" + name +
"'>"
64 html += name +
": " + (ann[i].shortText || '(icon)')
65 html +=
" -> " + ann[i].text +
"</span><br/>";
67 document.getElementById(
"list").innerHTML = html;
74 for (var x =
10; x <
15; x +=
2) {
79 text: 'Stock Market Crash ' + x
84 series: 'another line',
91 cssClass: 'annotation',
92 clickHandler: function() {
93 document.getElementById(
"events").innerHTML +=
"special handler<br/>";
100 text: 'Parabola Annotation at same x-coord'
102 g.setAnnotations(annotations);
105 var x = last_ann +
2;
106 var annnotations = g.annotations();
115 g.setAnnotations(annotations);
118 function bottom(el) {
119 var to_bottom = true;
120 if (el.value != 'Shove to bottom') to_bottom = false;
122 var anns = g.annotations();
123 for (var i =
0; i < anns.length; i++) {
124 anns[i].attachAtBottom = to_bottom;
126 g.setAnnotations(anns);
129 el.value = 'Lift back up';
131 el.value = 'Shove to bottom';
138 annotationClickHandler: function(ann, point, dg, event) {
139 eventDiv.innerHTML +=
"click: " + nameAnnotation(ann) +
"<br/>";
141 annotationDblClickHandler: function(ann, point, dg, event) {
142 eventDiv.innerHTML +=
"dblclick: " + nameAnnotation(ann) +
"<br/>";
144 annotationMouseOverHandler: function(ann, point, dg, event) {
145 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
146 saveBg = ann.div.style.backgroundColor;
147 ann.div.style.backgroundColor = '#ddd';
149 annotationMouseOutHandler: function(ann, point, dg, event) {
150 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
151 ann.div.style.backgroundColor = saveBg;
154 pointClickCallback: function(event, p) {
155 // Check if the point is already annotated.
156 if (p.annotation) return;
163 text:
"Annotation #" + num
165 var anns = g.annotations();
167 g.setAnnotations(anns);