Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use d3 log scale instead of linear scale

I'm trying to do a chart based on http://mbostock.github.com/d3/talk/20111116/bar-hierarchy.html, the only difference being that I'd like to use a log scale for the x-axis.

Here's my fiddle: http://jsfiddle.net/JhDVC/5/

As you can see, the x-axis is defined at line 4:

x = d3.scale.linear().range([0, w]),

If I change it for

x = d3.scale.log().range([0, w]),

Then it doesn't work (nothing is rendered), throwing these error messages:

Error: Invalid value for <rect> attribute width="NaN" 

Changing the domain setting from

x.domain([0, root.value]).nice();

to

x.domain([1, root.value]).nice();

shows me the z axis (names) but still no bars or values.

like image 390
luisfarzati Avatar asked Mar 01 '13 17:03

luisfarzati


1 Answers

There are a few other places where the domain for the scale is set. You need to update those as well.

Working jsfiddle here.

And here's some code so that it allows me to post this:

x.domain([1, root.value]).nice();
like image 129
Lars Kotthoff Avatar answered Sep 19 '22 11:09

Lars Kotthoff