Makanz / chartjs-plugin-trendline

This plugin draws an linear trendline in your Chart. Made for Chart.js > 3.0
MIT License
83 stars 57 forks source link

Issue with Vite and Docker #91

Closed IlyaLisov closed 3 weeks ago

IlyaLisov commented 1 month ago

I use Vite for building production code. I used this import for trendline to code be compiled:

import * as trendlinePlugin from "chartjs-plugin-trendline";

Chart.register(
    ...,
    trendlinePlugin
);

After opening components with chart, I get exceptions like this: telegram-cloud-photo-size-2-5244859263120175125-x

After removing trendline from registration problem dissappeared. In local deployment everything works

Versions:

"chart.js": "^4.2.1",
"chartjs-plugin-trendline": "^2.1.1",
Makanz commented 1 month ago

Make sure you are using the latest version 2.1.2. there is a bug in 2.1.1.

IlyaLisov commented 1 month ago

I still have same exception

IlyaLisov commented 1 month ago

I think problem is in my import. Because I imported *, Chart.js can do something in registration and get an error. So Without import * I can't build project with Vite. I think I need to change something in my config

Makanz commented 1 month ago

I tried with Vite and following worked for me.

import { Chart, registerables } from 'chart.js';
import 'chartjs-plugin-trendline';

Chart.register(...registerables);
qadzek commented 1 month ago

This is working for me. I am using Vite, React and TypeScript:

import { otherStuff, Chart as ChartJS } from 'chart.js';
import chartTrendLine from 'chartjs-plugin-trendline';

ChartJS.register( otherStuff, chartTrendLine );