3

this is my fiddle, which I am building with from this example

what is the best way to convert the text lables from 0.08 to 8% format.

This is my attempt, but is there a better/other way?

.text(function(d) { return Math.floor(d.frequency*100)+"%"; });

HattrickNZ
  • 4,373
  • 15
  • 54
  • 98

1 Answers1

4

The most common way to do it (let's call it the "d3 way") is to use the d3 formatting functions:

var format = d3.format("%");

Here is the Fiddle: https://jsfiddle.net/cr91xf1t/

You can play with several built in formats, or even create your own. Have a look here: http://bl.ocks.org/zanarmstrong/05c1e95bf7aa16c4768e

Gerardo Furtado
  • 100,839
  • 9
  • 121
  • 171