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

How to keep a point which was clicked as active like it is during hover. #2002

Open
HuzaifaBilal opened this issue Aug 9, 2024 · 0 comments

Comments

@HuzaifaBilal
Copy link

HuzaifaBilal commented Aug 9, 2024

I have written the following code to set the point that was clicked as Active element but it just doesn't work any suggestions

  private onClick = (
    event: ChartEvent,
    elements: ActiveElement[],
    chart: Chart,
  ) => {
    if (elements.length) {
      const element = elements[0];
      const datasetIndex = element.datasetIndex;
      const dataIndex = element.index;
      const dataset = chart.data.datasets[datasetIndex];
      const dataValue = dataset.data[dataIndex];
      chart.setActiveElements([
        {
          datasetIndex,
          index: dataIndex,
        },
      ]);
      chart.tooltip?.setActiveElements(
        [
          {
            datasetIndex,
            index: dataIndex,
          },
        ],
        dataValue as Point,
      );

      chart.update();
    }  };
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

1 participant