question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting up Zoom with react-chartjs-2

See original GitHub issue

What is the proper way to setup zoom plugin with react-chartjs-2? Is it compatible?

I just ran npm install chartjs-plugin-zoom which installed the plugin and its hammerjs dependency and started configuring my chart options:

pan: {
  enabled: true,
  mode: 'x'
},
zoom: {
  enabled: true,
  mode: 'xy'
},

However this is not working. Am I skipping any step? I searched for react-chartjs-2 specific issues but found nothing. Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

15reactions
miguelperescommented, Feb 22, 2017

Solved: I don’t know if this is the proper way to do this, but I just imported the plugin in my chart component file:

import * as zoom from 'chartjs-plugin-zoom'

and the pan and zoom options started working. If there is no better approach, I think the issue can be closed! 😃

6reactions
jcrombezcommented, Jan 3, 2020

it has been a few years but if someone else want to do a reset button when using react (like @junbinku was asking) :

in your render you need to get the component reference, for example with a <Line> :

<button onClick={() => this.lineReference.chartInstance.handleZoomReset() }>Reset zoom</button>
<Line (here your data, options and so on)  ref={(reference) => this.lineReference = reference} />
Read more comments on GitHub >

github_iconTop Results From Across the Web

Zoom and Pan in react-chartjs-2 - Stack Overflow
One way to zoom as an example (at least for Mac), you can move your mouse pointer into the chart area, and then...
Read more >
chartjs-plugin-zoom
A zoom and pan plugin for Chart.js >= 3.0.0.
Read more >
chartjs-plugin-zoom examples - CodeSandbox
Learn how to use chartjs-plugin-zoom by viewing and forking example apps that make use of chartjs-plugin-zoom on CodeSandbox. ; Latest version2.0.0. LicenseMIT.
Read more >
chartjs-plugin-zoom - npm
chartjs -plugin-zoom ... For Chart.js 2.6.0 to 2.9.x support, use version 0.7.7 of this plugin. Panning can be done via the mouse or...
Read more >
chartjs-plugin-zoom - CodePen
P Create New Pen. S Save. ⇧ S Save As Private PRO. I Info Panel (if owned). CodePen requires JavaScript to render the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found