score:7
Accepted answer
2 things, you will have to register the zoomplugin as stated in the documentation by registering it either globally or inline (https://www.chartjs.org/chartjs-plugin-zoom/guide/integration.html#bundlers-webpack-rollup-etc), also your config was incorrect, the zoom option does not have an enabled
option, you will have to enable all the different zoom types appart, then it will work (https://www.chartjs.org/chartjs-plugin-zoom/guide/options.html#zoom-options)
import { Line, Chart } from "react-chartjs-2";
import React from "react";
import zoomPlugin from "chartjs-plugin-zoom";
Chart.register(zoomPlugin); // REGISTER PLUGIN
const Chart2 = (props) => {
const data = {
title: props.title,
labels: props.labels,
datasets: props.datasets
};
const options = {
maintainAspectRatio: false,
responsive: true,
elements: {
point: {
radius: 0
},
line: {
borderWidth: 1.5
}
},
scales: {
x: {
ticks: {
color: "rgba( 0, 0, 1)"
},
grid: {
color: "rgba(0, 0, 0, 1)"
}
},
y: {
min: 1,
max: 200000,
type: "logarithmic",
ticks: {
color: "rgba(0, 0, 0, 1)"
},
grid: {
color: "rgba(0, 0, 0, 1)"
}
}
},
plugins: {
zoom: {
zoom: {
wheel: {
enabled: true // SET SCROOL ZOOM TO TRUE
},
mode: "xy",
speed: 100
},
pan: {
enabled: true,
mode: "xy",
speed: 100
}
}
}
};
return (
<div>
<Line
type="line"
data={data}
options={options}
width={900}
height={450}
/>
</div>
);
};
export default Chart2;
Codesandbox link: https://codesandbox.io/s/react-chart-js-forked-cn6wh?file=/src/components/Chart.js
Source: stackoverflow.com
Related Query
- chartjs-plugin-zoom not working with my React project
- Chartjs not working with d3 from csv source
- chart.js v3 - data decimation not working with zoom plugin
- Chartjs with zoom plugin zooms too much with wheel just with single turn
- Bootstrap modal not working with chartjs line graph
- Chartjs with Vue, Bar Chart Border Radius not working
- Legend color not working with randomly generated background colors in chartjs pie chart
- ChartJs is not working in angular 4 with no errors
- ChartJs not working with this JSON Object
- Setting ChartJS plugin on vue-chartjs not working
- Annotation plugin not working with Chart.js 2.8.0
- ng2-Chart not working with newly created angular 10 project
- angular directive is not working with chartjs
- ChartJS Scatter plot with JSON list variable not working
- react-chartjs-2 with chartJs 3: Error "arc" is not a registered element
- Using CSS variables (color) with chart.js - "var(--primaryColor)" not working
- Bootstrap grid not working with canvas
- implement chartjs zoom with buttons
- Add zoom event handler to charts for chartjs with chartjs-plugin-zoom
- how to get React chartjs to resize back down with window
- Time Series Line chart js in react not working
- ChartJS multiple tooltip callbacks not working
- showing tooltips all the time in chartjs 2.4 not working
- ChartJS - radar chart options not working
- Bubble Chart in Chartjs not working
- Android: WebView with JavaScript for Chart.js not working properly
- Graph streaming real-time data with react and chartjs
- chartjs plugin datalabels does not show value on charts
- Chart.js stepSize not working with min
- code works fine on jsfiddle but one function is not working on website
More Query from same tag
- ChartJS pie chart, "filling" each segment to indicate another dimension
- Chartjs using array in label field
- Remove tooltip if has no label
- How to set default colour for bars in Chart.js
- Chart Is Not Created
- Chart.js responsive pie chart
- How add the sizes of the slices in the pie chart (at the top) in Chart.js?
- API data not loading in chart.js until element is inspected or page is resized
- issue with legend boxes in ChartJS
- generator-angular-fullstack cannot add angular-chart.js
- Is there a way to give a pie chart in chart.js a different color outer border than the border color between segments?
- How could I implement chartjs-plugin-datalabels in chartjs-node-canvas?
- Dynamic Chart in PHP using Chart js
- Chartjs Polar Area Chart - Data labels shown don't rotate with startAngle
- How to change z-index of chart js tooltip?
- Django show Graphs with ChartJS
- How do I create a chartjs bar chart?
- how can I show only 2 numbers on the xAxe in Chartjs having more than two numbers on the chart? (line chart)
- How to create an angular 7 component?
- Papaparse with chart.js not displaying csv value on the x axis
- Chart.js: Minimum value for x-axis at horizontal stacked bar chart
- How to populate entire box inside a React chart (between two axes)
- can't dispal 2 garphs on chart.js
- React Js and Chart Js (Line Chart)
- ChartJS: Two Titles for positive and negative part of y axis
- how to put a y-axis and x-axis label while using html and chartjs
- Chart.js overlapping tooltip text
- Displaying data from simple html form to display in chartjs
- How to remove the coloured rectangle(dataset label) in chartJS
- Loop through array of objects in Node