Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trendline not rendered for time scale #101

Open
GauntletPL opened this issue Jan 11, 2025 · 2 comments
Open

Trendline not rendered for time scale #101

GauntletPL opened this issue Jan 11, 2025 · 2 comments

Comments

@GauntletPL
Copy link

Hi,

With the chart configuration like below, I get the following error:

image

new Chart(
        document.querySelector('#test-trendline'),
        {
            type: 'line',
            data: {
                datasets: [
                    {
                        label: 'Dataset',
                        data: [
                            {date: new Date(2025, 0, 1), val: 10},
                            {date: new Date(2025, 0, 2), val: 20},
                            {date: new Date(2025, 0, 7), val: 30},
                            {date: new Date(2025, 0, 12), val: 10},
                            {date: new Date(2025, 0, 13), val: 40},
                        ],
                        parsing: {
                            xAxisKey: 'date',
                            yAxisKey: 'val'
                        },
                        trendlineLinear: {
                            colorMin: '#0000ff',
                            colorMax: '#0000ff',
                            lineStyle: 'solid',
                            width: 2,
                            xAxisKey: 'date',
                            yAxisKey: 'val',
                            projection: true
                        }
                    }
                ]
            },
            options: {
                scales: {
                    xAxis: {
                        type: 'time',
                        time: {
                            unit: 'day'
                        }
                    }
                },
                plugins: {
                    datalabels: false
                }
            }
        }
    );
@Makanz
Copy link
Owner

Makanz commented Jan 14, 2025

Try to add
chartjs-adapter-date-fns
and change options to this

options: { scales: { x: { type: 'timeseries', } } }

@GauntletPL
Copy link
Author

I am already using chartjs-adapter-luxon. And using timeseries scale isn't something that I'm really after.
Still, applying both changes you've proposed did not fix the problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants