I am using NVD3 scatter/ Bubble chart. This is a continuation from the question here. I am plotting the log base 2 values for the y axis. But I want the y axis to have the origi
Instead of directly calculating the log when you create your data array, leave it as is and then use a log scale for your axis.
To use a custom scale in NVD3, you pass it as a parameter to the chart.yScale(scale)
or chart.xScale(scale)
methods.
var chart = nv.models.lineChart()
.yScale( d3.scale.log() );
Just don't try to use a log scale for y values in a bar or area chart, since those automatically include 0 in the domain (and you'll get errors if you try to plot anything at log(0)
!)
A couple warnings:
Tick formating functions work different on log scales than for other scales; you'll probably want to just leave it as the default. See the docs (link above) for more info.
The .nice()
method doesn't seem to work very effectively on log scales; when I was playing around on the NVD3 live code site, a domain of [1,99] was resulting in a final tick value of 98.999999999 on the axis. You may want to explicitly check that the domain starts and ends at round numbers.
Also note that since you're never actually dealing with the calculated values for the logs (just with the relative positions on the scale) you don't need to specify a base to the logarithm. The docs mention a logScale.base(number) method but that seems to be obsolete...