Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw logarithmic line charts with nvd3

Tags:

d3.js

nvd3.js

Is there a way to draw logarithmic line charts with nvd3

like image 843
Andreas Köberle Avatar asked Feb 01 '13 14:02

Andreas Köberle


1 Answers

I'm not a nvd3/d3 expert, but I've made something which seems to work like this for the nv.models.lineChart:

chart.yScale(d3.scale.log());
chart.yAxis.tickValues([1,10,100,1000,10000,1000000]);
chart.forceY([1,1000000]);

Notes:

  1. The yScale function may be slightly different between models (chart.lines.yScale & cart.lines2.yScale on nv.models.lineWithFocusChart for example)
  2. This doesn't seem to work with all models
  3. D3 only supports base10 currently As of version 3.1.0 D3.js supports arbitrary logarithm base, usage example http://bl.ocks.org/mbostock/7621155
like image 94
throwaway112358 Avatar answered Oct 02 '22 20:10

throwaway112358