streamlinesocial / highcharts-regression

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

Trendline is different if points are away from X origin #95

Open Rumpelstinsk opened 5 years ago

Rumpelstinsk commented 5 years ago

I'm trying to add a trend line on a highcharts chart. However, the trend line is different If I set the points away from X axis origin.

It's easier to explain with an example.

This is my code:

var serieData = [
        [1000, 0.82],
        [240000, 0.85],
        [480000, 0.83],
        [1920000, 0.78],
        [3000000, 0.81]
    ];

  Highcharts.chart('container', {
            title: {
                text: "Speed"
            },
            chart: {
                type: 'scatter',
                zoomType: 'xy'
            },
            yAxis: {
                title: {
                    text: "Speed m/s"
                }
            },
            xAxis: {
                type: 'datetime',
                title: {
                    text: "Time hh:mm"
                }                
            },

            series: [{
                regression: true,
                regressionSettings: {
                    name: 'Tendencia',
                    type: 'polynomial',
                    order: 3,
                    color: 'rgba(223, 183, 83, .9)',
                    dashStyle: 'dash'
                },
                name: "Sample",
                color: 'rgba(223, 83, 83, .5)',
                data: serieData
            }],
            responsive: {
                rules: [{
                    condition: {
                        maxWidth: 500
                    },
                    chartOptions: {
                        legend: {
                            layout: 'horizontal',
                            align: 'center',
                            verticalAlign: 'bottom'
                        }
                    }
                }]
            }
        });

That code produces the next chart:

enter image description here

Now I want to move the points to their correct timestamp. So:

serieData = [
        [1519810440000, 0.82],
        [1519810800000, 0.85],
        [1519811280000, 0.83],
        [1519812480000, 0.78],
        [1519813620000, 0.81]
    ];

However, with that UTC values, the trend line is different:

enter image description here

You can reproduce the behaviour here: https://jsfiddle.net/5vLuwba8/

Any ideas?

phpepe commented 5 years ago

Thanks for reporting it Definitely we have issues with timestamps in the x-axis. Not sure if related with precision on the equation, when x values are high, I need to analyze it carefully - If you have any thoughts let me know please

El jue., 29 ago. 2019 a las 7:11, Rumpelstinsk (notifications@github.com) escribió:

I'm trying to add a trend line on a highcharts chart. However, the trend line is different If I set the points away from X axis origin.

It's easier to explain with an example.

This is my code:

var serieData = [ [1000, 0.82], [240000, 0.85], [480000, 0.83], [1920000, 0.78], [3000000, 0.81] ];

Highcharts.chart('container', { title: { text: "Speed" }, chart: { type: 'scatter', zoomType: 'xy' }, yAxis: { title: { text: "Speed m/s" } }, xAxis: { type: 'datetime', title: { text: "Time hh:mm" } },

        series: [{
            regression: true,
            regressionSettings: {
                name: 'Tendencia',
                type: 'polynomial',
                order: 3,
                color: 'rgba(223, 183, 83, .9)',
                dashStyle: 'dash'
            },
            name: "Sample",
            color: 'rgba(223, 83, 83, .5)',
            data: serieData
        }],
        responsive: {
            rules: [{
                condition: {
                    maxWidth: 500
                },
                chartOptions: {
                    legend: {
                        layout: 'horizontal',
                        align: 'center',
                        verticalAlign: 'bottom'
                    }
                }
            }]
        }
    });

That code produces the next chart:

[image: enter image description here] https://i.stack.imgur.com/MqEeT.png

Now I want to move the points to their correct timestamp. So:

serieData = [ [1519810440000, 0.82], [1519810800000, 0.85], [1519811280000, 0.83], [1519812480000, 0.78], [1519813620000, 0.81] ];

However, with that UTC values, the trend line is different:

[image: enter image description here] https://i.stack.imgur.com/pM8rT.png

You can reproduce the behaviour here: https://jsfiddle.net/5vLuwba8/

Any ideas?

— 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/95?email_source=notifications&email_token=AAP5GLUUXTFFDVISXINYAA3QG6OEBA5CNFSM4ISANG5KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIE7WBQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AAP5GLSVDKC6OPHZUCK2ACDQG6OEBANCNFSM4ISANG5A .