Skip to content

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

@Rumpelstinsk

Description

@Rumpelstinsk

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions