<!--[if IE]>
<script type="text/javascript" src="excanvas.js"></script>
<![endif]-->
+ <!--
+ <script type="text/javascript" src="dygraph-combined.js"></script>
+ -->
<script type="text/javascript" src="../strftime/strftime-min.js"></script>
<script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
<script type="text/javascript" src="../dygraph-canvas.js"></script>
</style>
</head>
<body>
+ <h3>Annotations Demo</h3>
+ <p>Click any point to add an annotation to it or click "Add Annotation".</p>
<input type="button" value="Add Annotation" onclick="add()" />
+ <input type="button" value="Shove to bottom" onclick="bottom(this)" />
<div id="events"> </div>
<div style="position:absolute; left:200px; top: 200px;" id="g"></div>
<div style="position:absolute; left:700px; top: 200px;" id="list"></div>
return "(" + ann.series + ", " + ann.x + ")";
}
- g = new DateGraph(
+ g = new Dygraph(
document.getElementById("g"),
function() {
var zp = function(x) { if (x < 10) return "0"+x; else return x; };
series: 'another line',
x: "20061013",
icon: 'dollar.png',
- iconWidth: 18,
- iconHeight: 23,
+ width: 18,
+ height: 23,
tickHeight: 4,
text: 'Another one',
cssClass: 'annotation',
g.setAnnotations(annotations);
}
+ function bottom(el) {
+ var to_bottom = true;
+ if (el.value != 'Shove to bottom') to_bottom = false;
+
+ var anns = g.annotations();
+ for (var i = 0; i < anns.length; i++) {
+ anns[i].attachAtBottom = to_bottom;
+ }
+ g.setAnnotations(anns);
+
+ if (to_bottom) {
+ el.value = 'Lift back up';
+ } else {
+ el.value = 'Shove to bottom';
+ }
+ }
+
var saveBg = '';
+ var num = 0;
g.updateOptions( {
annotationClickHandler: function(ann, point, dg, event) {
eventDiv.innerHTML += "click: " + nameAnnotation(ann) + "<br/>";
annotationMouseOutHandler: function(ann, point, dg, event) {
document.getElementById(nameAnnotation(ann)).style.fontWeight = 'normal';
ann.div.style.backgroundColor = saveBg;
+ },
+
+ pointClickCallback: function(event, p) {
+ // Check if the point is already annotated.
+ if (p.annotation) return;
+
+ // If not, add one.
+ var ann = {
+ series: p.name,
+ xval: p.xval,
+ shortText: num,
+ text: "Annotation #" + num
+ };
+ var anns = g.annotations();
+ anns.push(ann);
+ g.setAnnotations(anns);
+
+ num++;
}
});
</script>