Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use C3 and D3 together?

I'm looking into charting libraries and I'm very impressed by the power of D3, but I'm kind of mind-boggled by its documentation. It would be a much easier decision to go with C3 instead if I knew that I could still use D3 to fill in whatever limitations C3 has.

So is it possible, with C3, to use D3 functionality to enhance charts generated with C3?

like image 202
B T Avatar asked Apr 10 '15 20:04

B T


People also ask

What is C3 and D3?

js is a JavaScript library for manipulating documents based on data. c3. js is a Javascript library which makes it easy to generate D3-based charts (less code to write). highchart is a Javascript charting framework.

Why should I use D3?

D3 helps you bring data to life using HTML, SVG and CSS. D3's emphasis on web standards gives you the full capabilities of modern browsers without tying yourself to a proprietary framework, combining powerful visualization components and a data-driven approach to DOM manipulation.

What is c3js?

C3. js is D3. js (D3 = Data-Driven Document) based JavaScript chart library. It is simple to use, customizable, and provides a nice API. It can be used to create visualizations using SVG, HTML, and CSS.

What Cannot you use D3 for?

D3 cannot easily conceal original data. If you're using data that you don't want shared, it can be challenging to use D3. D3 doesn't generate predetermined visualizations for you.


1 Answers

Your question is a little too vague to be answerable -- how exactly do you want to use d3 to modify a c3 generated chart?

That said, I'll take a shot at answering anyway. d3 is all about selecting/appending DOM elements, binding data to them and then manipulating them. After c3 does it's thing, there is nothing stopping you from selecting on what it generated and modifying it further.

Here's the simplest example I can think of:

// basic c3 line chart
var chart = c3.generate({
  data: {
    columns: [
      ['data1', 30, 200, 100, 400, 150, 250],
      ['data2', 50, 20, 10, 40, 15, 25]
    ]
  }
});

// select all it's "circles" and make them red
d3.selectAll(".c3-circle")
  .style("fill","red");

If I was you, though, I'd bite the bullet and just learn d3. If you are looking at a plotting library built on top of d3 and saying you need more, your code will be cleaner and more maintainable built from the ground up with straight d3.

like image 136
Mark Avatar answered Sep 18 '22 22:09

Mark