How to import c3.js with the dojo AMD loader

I came across the nice chart library c3.js, which is based on d3.js. In order to load it via an AMD require call with dojo, you also need to set the main property in the dojoConfig, e.g.:

dojoConfig = {
    packages: [
        { name: 'd3', location: '../../../d3', main: 'd3' }
        { name: 'c3', location: '../../../c3', main: 'c3' }
    ]
}

This will let you load c3.js in your module, e.g.:

define(['d3', 'c3', ...], function(d3, c3, ...) {
    ...
}
	

Join the Conversation

2 Comments

Your email address will not be published. Required fields are marked *

  1. Hi,

    Nice post.

    I wanted to know if you’ve ever tried to create Dojo Widget using C3 ? because I couldn’t find anything about it. I posted the issues here :
    http://stackoverflow.com/questions/30664043/how-to-create-dojo-widget-using-c3
    https://github.com/masayuki0812/c3/issues/1197

    The only thing I could do is creating the module like above, but the problem is, when I generate c3 chart, I can’t see it … I have to Ctrl+T to create a new tab in my navigator, then return to the tab containing my chart in order to see it … Maybe there is something that could help refreshing the page ..? It’s the first time I use Dojo so maybe i miss something ..?

    Thank you !