+
+ var last_ann = 0;
+ annotations = [];
+ for (var x = 10; x < 15; x += 2) {
+ annotations.push( {
+ series: 'sine wave',
+ x: "200610" + x,
+ shortText: x,
+ text: 'Stock Market Crash ' + x
+ } );
+ last_ann = x;
+ }
+ annotations.push( {
+ series: 'another line',
+ x: "20061013",
+ icon: 'dollar.png',
+ width: 18,
+ height: 23,
+ tickHeight: 4,
+ text: 'Another one',
+ cssClass: 'annotation',
+ clickHandler: function() {
+ document.getElementById("events").innerHTML += "special handler<br/>";
+ }
+ } );
+ g.setAnnotations(annotations);
+
+ function add() {
+ var x = last_ann + 2;
+ var annnotations = g.annotations();
+ annotations.push( {
+ series: 'line',
+ x: "200610" + x,
+ shortText: x,
+ text: 'Line ' + x,
+ tickHeight: 10
+ } );
+ last_ann = x;
+ 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/>";
+ },
+ annotationDblClickHandler: function(ann, point, dg, event) {
+ eventDiv.innerHTML += "dblclick: " + nameAnnotation(ann) + "<br/>";
+ },
+ annotationMouseOverHandler: function(ann, point, dg, event) {
+ document.getElementById(nameAnnotation(ann)).style.fontWeight = 'bold';
+ saveBg = ann.div.style.backgroundColor;
+ ann.div.style.backgroundColor = '#ddd';
+ },
+ 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++;
+ }
+ });