0

Regarding - d3pie.js (plugin for d3.js) ,

Suppose I have a data array of objects with both - label and value (number type) properties each one .

Currently the value is displayed as it is , I want to display it in specify format such - $2,000 instead of 2000 and etc ..

I tried to add another property except label and value , say - formattedValue, and then set it in -

"inner": {
    "format": "formattedValue"
}

but the d3pie doesn't consider it and no value displayed .

How could I archive this ?

URL87
  • 10,667
  • 35
  • 107
  • 174

1 Answers1

1

I took a quick look at the plugin and it doesn't look to support passing your own format function. A quick hack to switch those labels could be (after drawing the pie chart):

setTimeout(function() {
  d3.selectAll('.p0_segmentValue-inner')
    .each(function(d) {
      d3.select(this).text('$'+d.value.formatMoney(0));
    })
}, 200);

Example here.

The formatMoney prototype stolen from here.

Community
  • 1
  • 1
Mark
  • 106,305
  • 20
  • 172
  • 230