4 <link rel=
"stylesheet" href=
"../css/dygraph.css">
7 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
10 For production (minified) code, use:
11 <script type=
"text/javascript" src=
"dygraph-combined.js"></script>
13 <script type=
"text/javascript" src=
"../dist/dygraph.js"></script>
15 <style type=
"text/css">
21 <h3>Annotations Demo
</h3>
22 <p>Click any point to add an annotation to it or click
"Add Annotation".
</p>
23 <input type=
"button" value=
"Add Annotation" onclick=
"add()" />
24 <input type=
"button" value=
"Shove to bottom" onclick=
"bottom(this)" />
25 <div id=
"events"> </div>
26 <div style=
"position:absolute; left:200px; top: 200px;" id=
"g_div"></div>
27 <div style=
"position:absolute; left:700px; top: 200px;" id=
"list"></div>
29 <script type=
"text/javascript">
30 var eventDiv = document.getElementById(
"events");
31 function nameAnnotation(ann) {
32 return
"(" + ann.series +
", " + ann.x +
")";
36 var graph_initialized = false;
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, is_initial) {
60 graph_initialized = true;
61 if (annotations.length
> 0) {
62 g.setAnnotations(annotations);
66 var ann = g.annotations();
68 for (var i =
0; i < ann.length; i++) {
69 var name = nameAnnotation(ann[i]);
70 html +=
"<span id='" + name +
"'>"
71 html += name +
": " + (ann[i].shortText || '(icon)')
72 html +=
" -> " + ann[i].text +
"</span><br/>";
74 document.getElementById(
"list").innerHTML = html;
80 for (var x =
10; x <
15; x +=
2) {
85 text: 'Stock Market Crash ' + x
90 series: 'another line',
96 tickColor: 'indianred',
99 cssClass: 'annotation',
100 clickHandler: function() {
101 document.getElementById(
"events").innerHTML +=
"special handler<br/>";
108 text: 'Parabola Annotation at same x-coord'
111 if (graph_initialized) {
112 g.setAnnotations(annotations);
116 var x = last_ann +
2;
117 var annnotations = g.annotations();
126 g.setAnnotations(annotations);
129 function bottom(el) {
130 var to_bottom = true;
131 if (el.value != 'Shove to bottom') to_bottom = false;
133 var anns = g.annotations();
134 for (var i =
0; i < anns.length; i++) {
135 anns[i].attachAtBottom = to_bottom;
137 g.setAnnotations(anns);
140 el.value = 'Lift back up';
142 el.value = 'Shove to bottom';
149 annotationClickHandler: function(ann, point, dg, event) {
150 eventDiv.innerHTML +=
"click: " + nameAnnotation(ann) +
"<br/>";
152 annotationDblClickHandler: function(ann, point, dg, event) {
153 eventDiv.innerHTML +=
"dblclick: " + nameAnnotation(ann) +
"<br/>";
155 annotationMouseOverHandler: function(ann, point, dg, event) {
156 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
157 saveBg = ann.div.style.backgroundColor;
158 ann.div.style.backgroundColor = '#ddd';
160 annotationMouseOutHandler: function(ann, point, dg, event) {
161 document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
162 ann.div.style.backgroundColor = saveBg;
165 pointClickCallback: function(event, p) {
166 // Check if the point is already annotated.
167 if (p.annotation) return;
174 text:
"Annotation #" + num
176 var anns = g.annotations();
178 g.setAnnotations(anns);