Pri*_*nce 9 svg d3.js angularjs nvd3.js
我尝试了以下代码,
d3.scale.log().domain([1,4]).range([h, 0]);
Run Code Online (Sandbox Code Playgroud)
在轴中,我在轴值中获得1e + 0,2e + 0,3e + 0,4e + 0的值.但我需要lograthmic值,如10,100,1000,10000 ..等等....
min*_*omi 19
将log.scales tickFormat与轴tickFormat功能结合使用.
例如.设置1 - > 10000对数刻度:
var s = d3.scale.log().domain([1, 10000]).range([1000, 0])
Run Code Online (Sandbox Code Playgroud)
然后,设置轴:
var axis = d3.svg.axis().scale(s).tickFormat(function (d) {
return s.tickFormat(4,d3.format(",d"))(d)
})
Run Code Online (Sandbox Code Playgroud)
例
我们想要4个刻度 - 每个10的功率一个 - 并用逗号格式化为数字.
在此处了解有关格式化的更多信息:https:
//github.com/mbostock/d3/wiki/Formatting
在此处了解有关日志比例的更多信息:https:
//github.com/mbostock/d3/wiki/Quantitative-Scales#wiki-log
和轴:https:
//github.com/mbostock/d3/wiki/SVG-Axes#wiki-tickSize