C3 Graphs On Load Callback [closed]

ⅰ亾dé卋堺 提交于 2019-12-22 07:21:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!