6 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
9 For production (minified) code, use:
10 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
12 <script type=
"text/javascript" src=
"../dist/dygraph.js"></script>
14 <style type=
"text/css">
20 <h3>Annotations Demo
</h3>
21 <p>Click any point to add an annotation to it or click
"Add Annotation".
</p>
22 <input type=
"button" value=
"Add Annotation" onclick=
"add()" />
23 <input type=
"button" value=
"Shove to bottom" onclick=
"bottom(this)" />
24 <div id=
"events"> </div>
25 <div style=
"position:absolute; left:200px; top: 200px;" id=
"g_div"></div>
26 <div style=
"position:absolute; left:700px; top: 200px;" id=
"list"></div>
28 <script type=
"text/javascript">
29 var eventDiv = document.getElementById(
"events");
30 function nameAnnotation(ann) {
31 return
"(" + ann.series +
", " + ann.x +
")";
35 var graph_initialized = false;
38 document.getElementById(
"g_div"),
40 var zp = function(x) { if (x <
10) return
"0"+x; else return x; };
41 var r =
"date,parabola,line,another line,sine wave\n";
42 for (var i=
1; i<=
31; i++) {
43 r +=
"200610" + zp(i);
44 r +=
"," +
10*(i*(
31-i));
46 r +=
"," +
10*(
250 -
8*i);
47 r +=
"," +
10*(
125 +
125 * Math.sin(
0.3*i));
57 drawCallback: function(g, is_initial) {
59 graph_initialized = true;
60 if (annotations.length
> 0) {
61 g.setAnnotations(annotations);
65 var ann = g.annotations();
67 for (var i =
0; i < ann.length; i++) {
68 var name = nameAnnotation(ann[i]);
69 html +=
"<span id='" + name +
"'>"
70 html += name +
": " + (ann[i].shortText || '(icon)')
71 html +=
" -> " + ann[i].text +
"</span><br/>";
73 document.getElementById(
"list").innerHTML = html;
79 for (var x =
10; x <
15; x +=
2) {
84 text: 'Stock Market Crash ' + x
89 series: 'another line',
96 cssClass: 'annotation',
97 clickHandler: function() {
98 document.getElementById(
"events").innerHTML +=
"special handler<br/>";
105 text: 'Parabola Annotation at same x-coord'
108 if (graph_initialized) {
109 g.setAnnotations(annotations);
113 var x = last_ann +
2;
114 var annnotations = g.annotations();
123 g.setAnnotations(annotations);
126 function bottom(el) {
127 var to_bottom = true;
128 if (el.value != 'Shove to bottom') to_bottom = false;
130 var anns = g.annotations();
131 for (var i =
0; i < anns.length; i++) {
132 anns[i].attachAtBottom = to_bottom;
134 g.setAnnotations(anns);
137 el.value = 'Lift back up';
139 el.value = 'Shove to bottom';
146 annotationClickHandler: function(ann, point, dg, event) {
147 eventDiv.innerHTML +=
"click: " + nameAnnotation(ann) +
"<br/>";
149 annotationDblClickHandler: function(ann, point, dg, event) {
150 eventDiv.innerHTML +=
"dblclick: " + nameAnnotation(ann) +
"<br/>";
152 annotationMouseOverHandler: function(ann, point, dg, event) {
153 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
154 saveBg = ann.div.style.backgroundColor;
155 ann.div.style.backgroundColor = '#ddd';
157 annotationMouseOutHandler: function(ann, point, dg, event) {
158 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
159 ann.div.style.backgroundColor = saveBg;
162 pointClickCallback: function(event, p) {
163 // Check if the point is already annotated.
164 if (p.annotation) return;
171 text:
"Annotation #" + num
173 var anns = g.annotations();
175 g.setAnnotations(anns);