Help with a small modification to hierarchical bar charts

625 views
Skip to first unread message

Sean Cook

unread,
Jan 15, 2013, 4:33:57 PM1/15/13
to d3...@googlegroups.com
Hello all! First time poster and first time user here with a quick question.

I have been playing with the hierarchical bar chart example here:


A few questions come up...please keep in my mind my general ignorance of SVG and js.

1. What i would like to do is make the higher level bars equal to the mean of the children, rather than the sum. I have been playing with this for a few hours and it's not jumping out at me. I think if someone were to highlight the general area it wouldn't be a problem for me to get it done. I originally thought it was in the html file, but am  starting to think it must be in the layout.js file. A point in the right direction would be awesome!

2. I would like to replace the numbers on the x-axis with string labels. Where would be the best spot and method to implement that change?

Sorry for the n00b questions, but thanks in advance!

Sean


Chris Viau

unread,
Jan 15, 2013, 5:25:38 PM1/15/13
to d3...@googlegroups.com
Here are some information just to get you started. 

-The width of each bar is set in the bar function (line 216): .attr("width", function(d) { return x(d.value); })
-This d.value is provided by the partition layout according to the value accessor set on line 46. So it is the "size" value in the json file
-The x() function is just a scale to map from data to pixel space. 

So it seems to me that the width of each bar is set according to the value of the json, which is hardcoded as a sum of the children. I can be wrong, but if you want a mean, you would maybe have to grab these values, recompute a mean and reinject it into the json (or compute it on the fly).

Sean Cook

unread,
Jan 15, 2013, 5:49:28 PM1/15/13
to d3...@googlegroups.com
That all makes perfect sense, but I suppose what i am missng is where the hard coded "sum of children" rule is. d3.js?

Sean Cook

unread,
Jan 15, 2013, 6:16:45 PM1/15/13
to d3...@googlegroups.com
Alright, I got this....I had to add v = v/1; at line 1065 is d3.layout.js in the recurse function. Thanks for your help, I wouldn't have gotten there without your help!
Message has been deleted

Kasper Schjødt-Hansen

unread,
Aug 8, 2019, 4:46:24 PM8/8/19
to d3-js
Hi Sean

I am trying to do a similar thing in D3.v4. Do you know how to do this?
Reply all
Reply to author
Forward
0 new messages