使用d3对数标度而不是线性标度 [英] Use d3 log scale instead of linear scale
问题描述
我想根据 http://mbostock.github.com制作图表/d3/talk/20111116/bar-hierarchy.html ,唯一的区别是我想对x轴使用对数标度。
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.
这是我的小提琴: http://jsfiddle.net/JhDVC/5/
如您所见,x轴在第4行定义:
As you can see, the x-axis is defined at line 4:
x = d3.scale.linear().range([0, w]),
p>
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"
从
x.domain([0, root.value]).nice();
到
x.domain([1, root.value]).nice();
显示z轴(名称),但仍然没有条形或值。
shows me the z axis (names) but still no bars or values.
推荐答案
还有一些其他地方设置了标尺的域。您还需要更新这些内容。
There are a few other places where the domain for the scale is set. You need to update those as well.
工作jsfiddle 这里。
Working jsfiddle here.
这里有一些代码,让我可以发布:
And here's some code so that it allows me to post this:
x.domain([1, root.value]).nice();
这篇关于使用d3对数标度而不是线性标度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!