streamlinesocial / highcharts-regression

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

Polynomial Regression fails when y-axis data contains 0 value #100

Open markoberholzer-es opened 4 years ago

markoberholzer-es commented 4 years ago

Description: Polynomial regression fails when any point has a y-axis value of 0.

Steps to reproduce: Configure Chart with the following data: $(function() { $('#container').highcharts({ chart: { type: 'scatter' }, legend: { verticalAlign: 'top', }, series: [{ regression: true, regressionSettings: { type: 'polynomial', order: 2 }, data: [ [1, 50], [5,0], [10, 50] ] }] }); });

Actual Result: A linear line with the equation of y=0x^x + 0x +50 is drawn

Expected Result: A polynomial regression curve with the equation of y=2.5x^2 -27.5x + 75 should be drawn

Demo: http://jsfiddle.net/snoopliving/jxfgst4q/6/

Cause: Issue is most likely caused at the following line: https://github.com/streamlinesocial/highcharts-regression/blob/master/highcharts-regression.js#L397