What does d3.layout.pie().value() do?

1,631 views
Skip to first unread message

Aneesha Bakharia

unread,
Nov 24, 2012, 6:35:49 AM11/24/12
to d3...@googlegroups.com
Hi

I am wondering if I can specify an array of values that can be passed to the pie layout.
eg 
.data(d3.layout.pie().value(function(dreturn d.vals}))

where vals is an array of the values for the pie chart.
var data [
    name "Name 1"
      count40,
      vals [25,  252525},
    name "Name 2"
      count80,
      vals [25,  252525]},
    name "Name 3"
      count20,
      vals [25,  252525]},
    name "Name 4"
      count50,
      vals [25,  252525]}]

Essentially I am trying to make a clustered bubble chart with made up of pie charts.
Code is here: http://jsfiddle.net/aneesha/S9y9L/4/

Aneesha

Chris Viau

unread,
Nov 24, 2012, 11:38:16 AM11/24/12
to d3...@googlegroups.com
You have set the accessor with the value method, but not the actual data for the pie layout.

.data(d3.layout.pie().value(function(d) { return d.vals; })(nodes))

Keep in mind that the pie layout is a function returning a function. The previous line could be rewritten like this:

var pie = d3.layout.pie();
// pie is a functions with attributes, i.e., a value accessor
pie.value(function(d) { return d.vals; });
// and here we set the values
var pieData = pie(nodes)
...
.data(pieData)

Your code is still not totally working with this fix, but one problem at a time ;)

Chris Viau

unread,
Nov 24, 2012, 12:52:24 PM11/24/12
to d3...@googlegroups.com
I only tried to show that your pie value could not find any dataset to access. But in your case, the values should be grabbed from the data already bound to elements, so my advice was not so relevant. I'm trying to rethink your data-binding structure starting from http://bl.ocks.org/1305111

newbiesj

unread,
Jul 24, 2015, 4:28:05 PM7/24/15
to d3-js, aneesha....@gmail.com
Hi: 

I came across this question, and I'm in the same situation and beyond, I need to put multiple pies on the geomap, I wonder how this problem was solved? mind sharing ? 

Thanks 
Reply all
Reply to author
Forward
0 new messages