Gathering detailed insights and metrics for @lichtblick/chartjs-plugin-zoom
Gathering detailed insights and metrics for @lichtblick/chartjs-plugin-zoom
Gathering detailed insights and metrics for @lichtblick/chartjs-plugin-zoom
Gathering detailed insights and metrics for @lichtblick/chartjs-plugin-zoom
npm install @lichtblick/chartjs-plugin-zoom
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
217 Commits
7 Branches
1 Contributors
Updated on 09 Oct 2024
JavaScript (98.88%)
TypeScript (1.12%)
Cumulative downloads
Total Downloads
Last day
-60%
16
Compared to previous day
Last week
-89.8%
160
Compared to previous week
Last month
829.9%
3,422
Compared to previous month
Last year
0%
3,992
Compared to previous year
1
1
27
A zoom and pan plugin for Chart.js >= 3.0.0-beta.13.
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 with a finger. Zooming is done via the mouse wheel or via a pinch gesture. Hammer.js is used for gesture recognition.
Run npm install --save chartjs-plugin-zoom
to install with npm
.
If including via a <script>
tag, make sure to include Hammer.js
as well:
1<script src="https://cdn.jsdelivr.net/npm/chart.js@next"></script> 2<script src="https://cdn.jsdelivr.net/npm/hammerjs@2.0.8"></script> 3<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-zoom@next"></script>
To configure the zoom and pan plugin, you can simply add new config options to your chart config.
1plugins: { 2 zoom: { 3 // Container for pan options 4 pan: { 5 // Boolean to enable panning 6 enabled: true, 7 8 // Panning directions. Remove the appropriate direction to disable 9 // Eg. 'y' would only allow panning in the y direction 10 // A function that is called as the user is panning and returns the 11 // available directions can also be used: 12 // mode: function({ chart }) { 13 // return 'xy'; 14 // }, 15 mode: 'xy', 16 17 // Which of the enabled panning directions should only be available 18 // when the mouse cursor is over one of scale. 19 overScaleMode: 'xy', 20 21 rangeMin: { 22 // Format of min pan range depends on scale type 23 x: null, 24 y: null 25 }, 26 rangeMax: { 27 // Format of max pan range depends on scale type 28 x: null, 29 y: null 30 }, 31 32 // On category scale, factor of pan velocity 33 speed: 20, 34 35 // Minimal pan distance required before actually applying pan 36 threshold: 10, 37 38 // Function called while the user is panning 39 onPan: function({chart}) { console.log(`I'm panning!!!`); }, 40 // Function called once panning is completed 41 onPanComplete: function({chart}) { console.log(`I was panned!!!`); }, 42 // Function called when pan fails because modifier key was not detected. 43 // event is the a hammer event that failed - see https://hammerjs.github.io/api#event-object 44 onPanRejected: function({chart, event}) { console.log(`I didn't start panning!`); } 45 }, 46 47 // Container for zoom options 48 zoom: { 49 // Boolean to enable zooming 50 enabled: true, 51 52 // Enable drag-to-zoom behavior 53 drag: true, 54 55 // Drag-to-zoom effect can be customized 56 // drag: { 57 // borderColor: 'rgba(225,225,225,0.3)' 58 // borderWidth: 5, 59 // backgroundColor: 'rgb(225,225,225)', 60 // animationDuration: 0 61 // }, 62 63 // Zooming directions. Remove the appropriate direction to disable 64 // Eg. 'y' would only allow zooming in the y direction 65 // A function that is called as the user is zooming and returns the 66 // available directions can also be used: 67 // mode: function({ chart }) { 68 // return 'xy'; 69 // }, 70 mode: 'xy', 71 72 // Which of the enabled zooming directions should only be available 73 // when the mouse cursor is over one of scale. 74 overScaleMode: 'xy', 75 76 rangeMin: { 77 // Format of min zoom range depends on scale type 78 x: null, 79 y: null 80 }, 81 rangeMax: { 82 // Format of max zoom range depends on scale type 83 x: null, 84 y: null 85 }, 86 87 // Speed of zoom via mouse wheel 88 // (percentage of zoom on a wheel event) 89 speed: 0.1, 90 91 // Minimal zoom distance required before actually applying zoom 92 threshold: 2, 93 94 // On category scale, minimal zoom level before actually applying zoom 95 sensitivity: 3, 96 97 // Function called while the user is zooming 98 onZoom: function({chart}) { console.log(`I'm zooming!!!`); }, 99 // Function called once zooming is completed 100 onZoomComplete: function({chart}) { console.log(`I was zoomed!!!`); }, 101 // Function called when wheel input occurs without modifier key 102 onZoomRejected: function({chart, event}) { console.log(`I didn't start zooming!`); } 103 } 104 } 105}
Programmatically resets the zoom to the default state. See samples/zoom-time.html for an example.
You can find documentation for Chart.js at www.chartjs.org/docs.
Examples for this plugin are available in the samples folder.
Prior to v0.4.0, this plugin was known as 'Chart.Zoom.js'. Old versions are still available on npm under that name.
Before submitting an issue or a pull request to the project, please take a moment to look over the contributing guidelines first.
chartjs-plugin-zoom.js is available under the MIT license.
No vulnerabilities found.
No security vulnerabilities found.