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

Chart type mismatch in onClick and getRelativePosition #12011

Open
alexkiro opened this issue Jan 29, 2025 · 0 comments
Open

Chart type mismatch in onClick and getRelativePosition #12011

alexkiro opened this issue Jan 29, 2025 · 0 comments
Labels
type: bug type: types Typescript type changes

Comments

@alexkiro
Copy link

Expected behavior

There shouldn't be any type error when writing something like this:

  options: {
    scales: {
      y: {
        beginAtZero: true,
      },
    },
    onClick(event, elements, chart) {
      const canvasPosition = getRelativePosition(event, chart);
      const dataX = chart.scales.x.getValueForPixel(canvasPosition.x);
      alert(dataX);
    },
  },

Current behavior

This type error is present:

Argument of type 'Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint | null)[], unknown>' is not assignable to parameter of type 'Chart'.
  Type 'Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint | null)[], unknown>' is missing the following properties from type 'Chart': _options, _aspectRatio, _layers, _metasets, and 40 more.typescript(2345)
(parameter) chart: Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint | null)[], unknown>

Reproducible sample

https://codesandbox.io/p/sandbox/reverent-noyce-x7wm8r

Optional extra steps/info to reproduce

No response

Possible solution

No response

Context

No response

chart.js version

v4.4.7

Browser name and version

No response

Link to your project

No response

@LeeLenaleee LeeLenaleee added the type: types Typescript type changes label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug type: types Typescript type changes
Projects
None yet
Development

No branches or pull requests

2 participants