// Only add the annotation CSS rule once we know it will be used.
Dygraph.addAnnotationRule();
this.annotations_ = ann;
+ if (!this.layout_) {
+ this.warn("Tried to setAnnotations before dygraph was ready. " +
+ "Try setting them in a drawCallback. See " +
+ "dygraphs.com/tests/annotation.html");
+ return;
+ }
+
this.layout_.setAnnotations(this.annotations_);
if (!suppressDraw) {
this.predraw_();
return "(" + ann.series + ", " + ann.x + ")";
}
+ annotations = [];
+ var graph_initialized = false;
+
g = new Dygraph(
document.getElementById("g_div"),
function() {
showRoller: true,
width: 480,
height: 320,
- drawCallback: function(g) {
+ drawCallback: function(g, is_initial) {
+ if (is_initial) {
+ graph_initialized = true;
+ if (annotations.length > 0) {
+ g.setAnnotations(annotations);
+ }
+ }
+
var ann = g.annotations();
var html = "";
for (var i = 0; i < ann.length; i++) {
);
var last_ann = 0;
- annotations = [];
for (var x = 10; x < 15; x += 2) {
annotations.push( {
series: 'sine wave',
shortText: 'P',
text: 'Parabola Annotation at same x-coord'
} );
- g.setAnnotations(annotations);
+
+ if (graph_initialized) {
+ g.setAnnotations(annotations);
+ }
function add() {
var x = last_ann + 2;