javascript - Math.log, a Natural logarithmic y scale for currency time-series? -


my attempts make y values scale logarithmic turning data upside-down.

i have vanilla js code , every implementation read tied in huge libraries of production code, not sure how/what extract, need guidance not put finger on problem weather sum or miss-use of math functions.

i testing drawing y 'data' canvas (no libraries used) x axis constant 2px difference

math.log uses e (2.718) default base have read.. should seeing price data on natural log scale wont work.

function logscale(data){     var log=data.slice(0);     var i=log.length;     while(i--){          log[i]=math.log(data[i]); // should natural don't see change          // log[i]=math.pow(math.log(data[i]),10); //upside-down          // log[i]=math.log(data[i])/math.ln10;  //no visible change when drawn canvas           }     console.dir(log);     return log;     } 

another attempt couple of weeks ago using data min, max , difference. removing infinity.

function ᐄlogarithm(data){     var lmax,lmin,ldif,logarithm,infinity;     lmax=math.max.apply(this,data);     lmin=math.min.apply(this,data);     ldif=(lmax-lmin);     logarithm=[];     infinity=[];     for(var i=data.length-1;i>=0;i--){         logarithm[i]=math.log((data[i]-lmin)/ldif);         if(logarithm[i]===-infinity){infinity.push(i);}         }     for(var i=0;i<=infinity.length-1;i++){logarithm.splice(infinity[i],1);}     return logarithm;     } 

the data looks different still not quite log scale. it vertically warped best describe it.

please note jsfiddle-ing won't work data bitcoin prices (real time) there no working code log scale there no way show comparison. bitcoin or other exchange data gets served these functions (if worked) transfom any data array log scale.

how d3 it? wrong code?


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -