bindTo for jquery object
So far I couldn't find a possibilty to bind the graph to the html of an jquery object. I think this would be a super enhancment to this library, as you could assign the element for the chart more dynamically and also set multiple equal graphs to separate html elements.
I have the problem, that the html structure is dynamically generated in php and I would have to set seperate chart-containers with the id generated with php.
As all the containers are style with css classes it would be awesome to just select them with jquery and then assign the chart based on the jquery object or it's html (withouth having to generate the ids).
Hi @Skullcrasher ,
I totally agree. I'll fix bindto logic and make it possible to accept element directly without id.
By the way, I think it would be good to create jQuery plugin that accepts options of c3 and generate by that option, like $('...').c3(options). I might try this too.
Hi, I think it's very easy to generate ID for element before calling C3. For instance you can use Identify() function of Prototypejs (http://prototypejs.org/doc/latest/dom/Element/identify) or create something similar yourself.
I don't like idea of jquery plugin as that will add new dependency to maintain. For future my suggestion is to allow both plain string and reference to DOM node in bindto variable. Then on init() function you could check what user gave and save the node to global variable. Then in places where d3.select(__bindto).node()... is used you can simply call d3.select(node).
Once implemented, the jquery users could do the following:
$('.myClass').forEach(function() {
c3.genereate(
{
bindto: this,
...
})
})
but this is not a critical feature, it's more for convenience I think
@lblb That is also the direction I was thinking of. Of course not only use jquery, but more a binding that jquery use is possible beneath the other/standard possibilities. Also a separate jquery wouldn't be that bad, as long as it use c3 optionally and is not integrated in the core.
I close this issue because c3 can accept reference to DOM as bindto option like:
var element = document.getElementById('chart');
c3.generate({
...
bindto: element,
...
})