pedrorod
Posts: 44
Joined: Sun Oct 23, 2011 2:25 pm

highcharts regression polynomial line equation decimals

Hi

I have a chart that makes a highcharts regression polynomial line and I need the equation.

The problem is that the equation shows :
0x2 + 0x + 29.93

The correct must be : −0.0000357x2+0.0048927x+28.9340796

when I change the :
decimalPlaces: 4,
it only change in R and R2.

How can I change the decimals in que equation formula or have the individual parts of the regression equation with decimals ?





Thanks






Image



Code: Select all

$(function() {
  $('#container').highcharts({
    chart: {
      type: 'scatter',   //spline
			
      zoomType: 'xy',
			
			
			
			 events: {
        load: function() {
					let chart = this;
					
					
          console.log(chart.legend.allItems[1].name);

					output = chart.legend.allItems[1].name;
					
					console.log(output)
        }
      }
			
			
			
			
			
			
			
    },
    title: {
      text: 'Polynomial regression - with extrapolation and different style'
    },
    subtitle: {
      text: 'Grupo BME '
    },
    xAxis: {
      title: {
        enabled: true,
        text: 'Caudal (l/m)'
      },
      startOnTick: true,
      endOnTick: true,
      showLastLabel: true
    },
    yAxis: {
      title: {
        text: 'Altura (mt)'
      }
    },
    legend: {
      layout: 'vertical',
      align: 'left',
      verticalAlign: 'top',
      x: 100,
      y: 70,
      floating: true,
      backgroundColor: '#FFFFFF',
      borderWidth: 1
    },
    plotOptions: {
      scatter: {
        marker: {
          radius: 5,
          states: {
            hover: {
              enabled: true,
              lineColor: 'rgb(100,100,100)'
            }
          }
        },
        states: {
          hover: {
            marker: {
              enabled: false
            }
          }
        },
        tooltip: {
          headerFormat: '<b>{series.name}</b><br>',
          pointFormat: '{point.x} l/m, {point.y} mt'
        }
      }
    },
    series: [{
      regression: true,
      regressionSettings: {
        type: 'polynomial',
				order: 2,
				lineWidth:  5,
				decimalPlaces: 4,
				name: "%eq | r2: %r",
				//name: 'equat'+'%eq' +'r:'+ '%r'+'r2:'+ '%r2',
			 hideInLegend: false ,
				
        color: 'rgba(223, 183, 83, .9)',
        dashStyle: 'dash'
      },
      name: 'Test input',
      color: 'rgba(223, 83, 83, .5)',
			

			
			
      data: [
   [925.5,2],
	[912,3.8],
	[889.5,4.8],
	[876,6.3],
	[725.25,14.3],
	[583.5,20.5],
	[447.75,23.5],
	[391.5,24.8],
	[230.25,28],
	[144,28.5],
	[58.5,29.3],
	[0.2,29.3],
       
      ]

    }]
  });
});







mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: highcharts regression polynomial line equation decimals

Hello pedrorod,

Thanks for contacting us with your question.

In the beginning I just want to point out that this is not our plugin, thus I might miss some informations that are crucial here.

The problem is indeed related to decimal places and it seems like it is not possible to solve it with API options. In _polynomial function coefficients are being rounded here:

Code: Select all

        for (var i = equation.length - 1; i >= 0; i--) {
            if (i > 1) string += Math.round(equation[i] * 100) / 100 + 'x^' + i + ' + ';
            else if (i == 1) string += Math.round(equation[i] * 100) / 100 + 'x' + ' + ';
            else string += Math.round(equation[i] * 100) / 100;
        }

        return {equation: equation, points: results, string: string};
You need to adjust these Math.round functions so that they show as many decimals places as you want. I have removed them completely.
Demo: https://jsfiddle.net/BlackLabel/z3c4xt2r/

Let me know if that was what you were looking for!
Regards!
Mateusz Bernacik
Highcharts Developer
pedrorod
Posts: 44
Joined: Sun Oct 23, 2011 2:25 pm

Re: highcharts regression polynomial line equation decimals

Hi

Many thanks for the answer.
I understand now and the solution is OK.


Thanks
mateusz.b
Posts: 2006
Joined: Tue Jul 13, 2021 11:34 am

Re: highcharts regression polynomial line equation decimals

You're welcome! In case of any further questions, feel free to contact us again.
Mateusz Bernacik
Highcharts Developer

Return to “Highcharts Usage”