svg - How can I get numeric values instead of Logarthmic values in D3 axis scale? -
i tried following code,
d3.scale.log().domain([1,4]).range([h, 0]);
in axis i'm getting values 1e+0, 2e+0, 3e+0, 4e+0 in axis value. need lograthmic values such 10, 100, 1000, 10000 ..etc....
use log.scale
's tickformat
in conjunction axis tickformat
function.
eg. set 1 -> 10000 log scale:
var s = d3.scale.log().domain([1, 10000]).range([1000, 0])
then, set axis:
var axis = d3.svg.axis().scale(s).tickformat(function (d) { return s.tickformat(4,d3.format(",d"))(d) })
example
we want 4 ticks - 1 each power of 10 - , formatted comma digit.
learn more formatting here:
https://github.com/mbostock/d3/wiki/formatting
learn more log scales here:
https://github.com/mbostock/d3/wiki/quantitative-scales#wiki-log
and axis:
https://github.com/mbostock/d3/wiki/svg-axes#wiki-ticksize