问题
I want to show checkboxes for every column in my dygraph. But I can't figure out when to get the names of my columns from dygraph using
g.getLabels().
It works when I call it manually after I know the graph has loaded. But how can I automate this? I couldn't find an event like "Dygraph.loaded" or a property like "Dygraph.hasLoaded". Is there some way to easily do this?
回答1:
This is what the .ready() method is designed to do:
g = new Dygraph(div, "/path/to/data.csv");
g.ready(function() {
var labels = g.labels();
...
});
The function you pass to ready()
will be called after the chart has been drawn for the first time.
If you pass CSV data or an array to the Dygraphs constructor, it will be called synchronously. If you pass a URL, it will be called asynchronously.
来源:https://stackoverflow.com/questions/26316435/is-there-an-dygraph-has-loaded-event