问题
I want to use some kind of callback function that will run some code once the C3 Graph is finished loading so that I can change the fill colors of certain points.
回答1:
Don't load any data in the initialization. Rather explicitly call the load event and pass the data in. Then you have access to the done
callback.
var chart = c3.generate({ /*...*/ });
chart.load({
columns: [['data1, 100, 200, 150, ...],
...
],
done: function() { /* whatever you need done here... */}
});
回答2:
The above didnt work for me, I used 'onrendered'
.
onrendered: function () { ... }
See here: https://c3js.org/reference.html#onrendered
回答3:
Try declaring an id
on the graph container (usually the svg
) with .attr("id", "GraphContainer")
.
After that, you can bind an .onload
to it. Something like this:
var SVGCont = document.getElementById("GraphContainer");
SVGCont.onload = function() {
// your code for when it's done loading
};
You can also use the event for when SVG elements are added to the DOM:
$(document).bind("DOMNodeInserted", function(e) {
// your code
});
来源:https://stackoverflow.com/questions/27028267/c3-graphs-on-load-callback