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 var graph_initialized = false;
42 document.getElementById(
"g_div"),
44 var zp = function(x) { if (x <
10) return
"0"+x; else return x; };
45 var r =
"date,parabola,line,another line,sine wave\n";
46 for (var i=
1; i<=
31; i++) {
47 r +=
"200610" + zp(i);
48 r +=
"," +
10*(i*(
31-i));
50 r +=
"," +
10*(
250 -
8*i);
51 r +=
"," +
10*(
125 +
125 * Math.sin(
0.3*i));
61 drawCallback: function(g, is_initial) {
63 graph_initialized = true;
64 if (annotations.length
> 0) {
65 g.setAnnotations(annotations);
69 var ann = g.annotations();
71 for (var i =
0; i < ann.length; i++) {
72 var name = nameAnnotation(ann[i]);
73 html +=
"<span id='" + name +
"'>"
74 html += name +
": " + (ann[i].shortText || '(icon)')
75 html +=
" -> " + ann[i].text +
"</span><br/>";
77 document.getElementById(
"list").innerHTML = html;
83 for (var x =
10; x <
15; x +=
2) {
88 text: 'Stock Market Crash ' + x
93 series: 'another line',
100 cssClass: 'annotation',
101 clickHandler: function() {
102 document.getElementById(
"events").innerHTML +=
"special handler<br/>";
109 text: 'Parabola Annotation at same x-coord'
112 if (graph_initialized) {
113 g.setAnnotations(annotations);
117 var x = last_ann +
2;
118 var annnotations = g.annotations();
127 g.setAnnotations(annotations);
130 function bottom(el) {
131 var to_bottom = true;
132 if (el.value != 'Shove to bottom') to_bottom = false;
134 var anns = g.annotations();
135 for (var i =
0; i < anns.length; i++) {
136 anns[i].attachAtBottom = to_bottom;
138 g.setAnnotations(anns);
141 el.value = 'Lift back up';
143 el.value = 'Shove to bottom';
150 annotationClickHandler: function(ann, point, dg, event) {
151 eventDiv.innerHTML +=
"click: " + nameAnnotation(ann) +
"<br/>";
153 annotationDblClickHandler: function(ann, point, dg, event) {
154 eventDiv.innerHTML +=
"dblclick: " + nameAnnotation(ann) +
"<br/>";
156 annotationMouseOverHandler: function(ann, point, dg, event) {
157 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
158 saveBg = ann.div.style.backgroundColor;
159 ann.div.style.backgroundColor = '#ddd';
161 annotationMouseOutHandler: function(ann, point, dg, event) {
162 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
163 ann.div.style.backgroundColor = saveBg;
166 pointClickCallback: function(event, p) {
167 // Check if the point is already annotated.
168 if (p.annotation) return;
175 text:
"Annotation #" + num
177 var anns = g.annotations();
179 g.setAnnotations(anns);