streamlinesocial / highcharts-regression

Linear and non-linear regression support for highcharts
MIT License
73 stars 64 forks source link

b value shown as 0 in name (%eq) when b value is very low (e.g. 0.000026 is shown as 0) #94

Open nikhilchoudhry opened 5 years ago

nikhilchoudhry commented 5 years ago

In the %eq y=bx+c, b value is always shown as 0 if it is very low (e.g. 0.000026 is shown as 0) please refer the attached image - I am trying to display the equation using %eq unde graph.

The decimal value property doesn't effect the %eq value.

Kindly suggest if I am missing something.

image image

nikhilchoudhry commented 5 years ago

I gave a quick look into your code and the following transforms the value to 0 in the %eq :

var string = 'y = ' + Math.round(gradient 100) / 100 + 'x + ' + Math.round(intercept 100) / 100;

instead of fixed rounding, can we use dynamic function like below, which rounds considering the nearest non zero values -

function roundOff(n) { return parseFloat(n.toExponential(Math.max(1,2+Math.log10(Math.abs(n))))); }

roundOff(0.000025) = 0.000025

phpepe commented 5 years ago

Yes, its rounding to units. I would add a new option for precision on the formula, in order to avoid affecting current users. Thanks for your contribution

El mié., 19 jun. 2019 a las 13:59, Nikhil Choudhry (< notifications@github.com>) escribió:

I gave a quick look into your code and the following transforms the value to 0 in the %eq :

var string = 'y = ' + Math.round(gradient * 100) / 100 + 'x + ' + Math.round(intercept * 100) / 100;

instead of fixed rounding, can we use dynamic function like below, which rounds considering the nearest non zero values -

function roundOff(n) { return parseFloat(n.toExponential(Math.max(1,2+Math.log10(Math.abs(n))))); }

roundOff(0.000025) = 0.000025

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/streamlinesocial/highcharts-regression/issues/94?email_source=notifications&email_token=AAP5GLTLR47QGVVG7TN7VS3P3JQYVA5CNFSM4HZIMTK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYCQHOA#issuecomment-503645112, or mute the thread https://github.com/notifications/unsubscribe-auth/AAP5GLT2I6DPHVTLQFRWM23P3JQYVANCNFSM4HZIMTKQ .