I abandoned what I was trying to do, which was to step through a list of
various chart types to see what would be the best for what I wanted to
display.
One of the things I wanted to look at was to create PNGs of the various
charts. But, I ran foul of the "ready" event handlers again.
Just before I drew the charts I used
google.visualization.events.addListener(theGraphs, 'ready', function() {
document.getElementById(imgLink).innerHTML = '<a target="_blank"
href="' + theGraphs.getChart().getImageURI() + '">Printable Graph</a>';
});
but I was getting "Cannot read property 'getImageURI' of null" errors.
Presumably because of the loop the drawing of these graphs is in, it was
running too fast for the event handler to catch?
I tried removing the event handler after the drawing of the charts using
google.visualization.events.removeListener(theGraphs);
and even
google.visualization.events.removeAllListeners(theGraphs);
I had thought of doing something like trying to count the number of times
the event was triggered and comparing that to the number of times the
function was called but went for a simpler, but probably not the best
method, of adding a setTimeout function.
setTimeout(function() {
document.getElementById(imgLink).innerHTML = '<a target="_blank"
href="' + theGraphs.getChart().getImageURI() + '">Printable Graph</a>';
}, 100);
theGraphs.draw();
Probably not the most elegant solution, but the delay of just 1/10 of a
second made the problems I've been having go away.
https://jsfiddle.net/brisray/z49jw264/706/
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-visualization-api/61e75da1-6262-4c40-8d83-94916cd50320%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.