reactchartjs / react-chartjs-2

React components for Chart.js, the most popular charting library
https://react-chartjs-2.js.org
MIT License
6.63k stars 2.36k forks source link

Programmatic Event Triggers #684

Closed davidkipstar closed 3 years ago

davidkipstar commented 3 years ago

Hello,

I am trying to trigger a hover from outside chartjs, for this I could find this approach but I am not understanding how to use it in this wrapper.

Somebody got any experience in this?

Kind regards

dangreen commented 3 years ago

@davidkipstar Hi. You can access chartjs instance using ref: https://github.com/reactchartjs/react-chartjs-2#how-do-i-access-my-charts-instance

const ref = useRef()

useEffect(() => {
  triggerHover(ref.current)
  triggerTooltip(ref.current)
}, [])

return <Doughnut ref={ref} data={data} options={options} />