score:7
First you need to Run npm install chartjs-plugin-zoom
to install with npm
then do import chartjs-plugin-zoom
in your .ts file and write plugin like this :
plugins: {
zoom: {
pan: {
enabled: true,
mode: 'x'
},
zoom: {
enabled: true,
mode: 'x'
}
}
},
score:1
I had used and work fine (Angular 12 - Chartjs 3.5.0):
1.
npm i chart.js -s
npm i chartjs-plugin-zoom -s
.2
import 'hammerjs';
import zoomPlugin from 'chartjs-plugin-zoom';
Chart.register(zoomPlugin);
render: Chart;
this.render = new Chart(ctx, {type: 'line',
data: {
labels: xxxxxxxx,
datasets: [
......
]
},
options: {
responsive: true,
interaction: {
mode: 'index',
intersect: false,
},
plugins: {
zoom: {
zoom: {
wheel: {
enabled: true,
},
pinch: {
enabled: true
},
mode: 'xy',
},
pan: {
enabled: true,
mode: 'xy',
},
}
}
},
}
score:5
Install chart.js and chartjs-plugin-zoom
npm i chart.js -s
npm i chartjs-plugin-zoom -s
In Component.ts file import Chart and chartjs-plugin-zoom
import { Chart } from 'chart.js';
import 'chartjs-plugin-zoom';
Logic to load chart
let myChart = new Chart('mapId', {
type: 'bar',
data: {
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
},
plugins: {
zoom: {
pan: {
enabled: true,
mode: 'xy'
},
zoom: {
enabled: true,
mode: 'xy'
}
}
}
}
});
myChart.render();
In Component.html
<canvas id="mapId"></canvas>
score:6
The zoom options should be configured under the options
not options.plugins
setting.
options: {
pan: {
enabled: true,
mode: 'x',
},
zoom: {
enabled: true,
mode: 'x',
},
responsive: true
}
See this fiddle -> http://jsfiddle.net/3sx8zon2/2/
Source: stackoverflow.com
Related Query
- How to zoom charts in chart.js using angular 7
- How to save Chart JS charts as image without black background using blobs and filesaver?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- How to send data to chart js using angular
- how to increase space between legend and chart in chartjs (ng2charts ) using angular
- How to customize tooltip on mouse hover of a polar area chart of Angular Charts
- How to display the values inside the pie chart of PrimeNG (chart) using JavaScript or Angular
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- Building Multiple Charts Using Chart JS in an Angular Application
- Chart changes different on zoom when using multiple charts with chart.js and flask
- How Can I Get An Instance of a ChartJS Bar Chart Using Angular
- How to add prefix to legend in ng charts using angular
- How to enable zoom plugin using Chart JS?
- How to display Json object in chart js consisting of lists created using Django rest framework in angular application
- How to take data from an API and create a chart on that using Chart.js and Angular 8?
- how to create line chart using chart.js in angular 2+
- How to run Chart.js samples using source code
- how to not repeat code while creating multiple charts in chart js
- How to add text inside the doughnut chart using Chart.js?
- How to add an on click event to my Line chart using Chart.js
- How to Draw Gantt chart using chart js or other libraries
- How to add images as labels to Canvas Charts using chart.js
- How to add text in centre of the doughnut chart using Chart.js?
- How to create stacked bar chart using react-chartjs-2?
- zoom and pan on charts in angular
- How to access labels array using chart plugin (Chart.pluginService.register) in Chartjs 2.x?
- How to display the labels in doughnut chart using ng2 charts?
- How to create single value Doughnut or Pie chart using Chart.js?
- Ng2-charts / chart.js - how to refresh/update chart - angular 4
- Extending Existing Chart Types angular chart js using chart js 2.0
More Query from same tag
- Chart.js HiLo chart example
- Get Array with json without _chartjs: {…}, push: ƒ, pop: ƒ, shift: ƒ, splice: ƒ, …]
- how to make scrollable the legends of pie chart ( chart js )
- Chart.JS custom y axis labels with text that has value
- ChartJs Not displaying data
- How can I add an event to chart.js legend?
- Parse HTML input value to php over javascript file
- Make labels of ChartJS radar in a few rows
- Why is only a single chart of three updated with react-chartjs-2?
- Chart.js align line graph to the left
- ChartJS works with Angular 5 while developing, but ng build fails
- Chart.js not initiating
- chart.js - user add the final point of the line
- How to set labels align left in Horizontal Bar using chart.js?
- Chart.js limit the display size of the chart
- Chart.js showing x-axis ticks even though set to false
- Usage for angular-chart : colors and fonts
- chart js stripline? like one from canvas
- Loading and updating dynamic charts with dynamic data (chart.js)
- labelling the pop up Chart js
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- Vuejs - Chartjs - turning a doughnut chart to a gauge - rotation
- Set minimum number of steps in line chart
- Can't get data into my Javascript function using Django
- Why does putting two data sets with a Time Cartesian axis in Chart.js cause two Y axis tick sets?
- Chart JS - How to display Label over Slices instead of text on hover
- How to make multiple horizontal bar chartjs
- Accordion won't take up height of chart for first click
- Chart.js how to inser values from json
- How to create a rounded rectangle using ChartJS