chartjs-plugin-trendline icon indicating copy to clipboard operation
chartjs-plugin-trendline copied to clipboard

Bug in 2.0.3: Error when first data point is 0, "The provided double value is non-finite"

Open tsnork opened this issue 2 years ago • 1 comments

when the first value in data array is 0

let data = {
    "labels": [
        202303,
        202304,
        202305,
        202306
    ],
    "datasets": [
        {
            "data": [
                0,
                1,
                3,
                6
            ],
            "label": "Test",
            "borderColor": "#409b8c",
            "trendlineLinear": {
                "style": "#409b8c",
                "lineStyle": "dotted",
                "width": 1,
                "projection": false
            }
        }
    ]
};

the following error gets thrown:

Uncaught TypeError: Failed to execute 'createLinearGradient' on 'CanvasRenderingContext2D': The provided double value is non-finite. at addFitter (chartjs-plugin-trendline.js:136:24)

Changing the first value to any int > 0 solves this issue, every other data point can be 0. Values < 0 cause this error as well.

let data = {
    "labels": [
        202303,
        202304,
        202305,
        202306
    ],
    "datasets": [
        {
            "data": [
                2
                0,
                3,
                6
            ],
            "label": "Test",
            "borderColor": "#409b8c",
            "trendlineLinear": {
                "style": "#409b8c",
                "lineStyle": "dotted",
                "width": 1,
                "projection": false
            }
        }
    ]
};

Here's a codepen with the reproducible issue:

https://codepen.io/tsnork/pen/RwqqaJg

Thx for your work with this library!

tsnork avatar Jul 28 '23 11:07 tsnork

I removed the "logarithmic" setting, and that made the chart start working. Now, I need to keep looking into why logarithmic scale caused this problem. @tsnork

Makanz avatar Aug 21 '23 19:08 Makanz