Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

d3 show number instead of percentages on pie chart

I'm drawing a graph to show how many people completed our app and how many people failed going through all the steps. To do this my company has decided to use the library d3 to show the charts. However, on the pie chart they want a whole number to show instead of the default percentage and I can't seem to find any documentation on this.

My code for this looks like this

 c3.generate({
      bindto: '.pieChart',
      data: {
       columns: [
           ['Started', Started],
           ['Completed', Completed]
        ],
           type: 'pie'
       }
   });

Any help would be appreciated!

like image 797
zazvorniki Avatar asked Jun 02 '15 18:06

zazvorniki


1 Answers

The documentation is pretty clear.

var chart = c3.generate({
  data: {
    columns: [
      ['data1', 30],
      ['data2', 50]
    ],
    type: 'pie'
  },
  pie: {
    label: {
      format: function(value, ratio, id) {
        return value;
      }
    }
  }
});

Example here.

like image 95
Mark Avatar answered Sep 19 '22 21:09

Mark