|
2 | 2 |
|
3 | 3 | Using the zoom and pan plugin is very simple. Once the plugin is [registered](./integration) zoom options provided to the chart will be used. In this example, scroll zoom is enabled. |
4 | 4 |
|
5 | | -```js chart-editor |
6 | | -/* <block:config:0> */ |
7 | | -const config = { |
8 | | - type: 'line', |
9 | | - data: { |
10 | | - labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], |
11 | | - datasets: [{ |
12 | | - label: 'My First Dataset', |
13 | | - data: [65, 59, 80, 81, 56, 55, 40], |
14 | | - fill: false, |
15 | | - borderColor: 'rgb(75, 192, 192)', |
16 | | - tension: 0.1 |
17 | | - }] |
18 | | - }, |
19 | | - options: { |
20 | | - plugins: { |
21 | | - zoom: { |
22 | | - zoom: { |
23 | | - wheel: { |
24 | | - enabled: true, |
25 | | - }, |
26 | | - pinch: { |
27 | | - enabled: true |
28 | | - }, |
29 | | - mode: 'xy', |
30 | | - } |
31 | | - } |
32 | | - } |
33 | | - } |
34 | | -} |
35 | | -/* </block:config> */ |
| 5 | +<playground-project id="projectUsage"></playground-project> |
| 6 | +<playground-preview project="projectUsage" style="height: 420px"></playground-preview> |
| 7 | +<playground-file-editor project="projectUsage" style="height: max-content"></playground-file-editor> |
36 | 8 |
|
37 | | -module.exports = { |
38 | | - actions: [ |
39 | | - { |
40 | | - name: 'Reset zoom', |
41 | | - handler: function(chart) { |
42 | | - chart.resetZoom() |
43 | | - } |
44 | | - } |
45 | | - ], |
46 | | - config |
47 | | -} |
48 | | -``` |
| 9 | +<script setup> |
| 10 | +import {onMounted} from 'vue'; |
| 11 | +import code from "./usage-example.js?raw"; |
| 12 | +import registerBundle from "../public/register.bundle.esm.js?raw"; |
| 13 | + |
| 14 | +onMounted(async () => { |
| 15 | + await import("playground-elements/playground-project.js"); |
| 16 | + await import("playground-elements/playground-file-editor.js"); |
| 17 | + await import("playground-elements/playground-preview.js"); |
| 18 | + |
| 19 | + const projElem = document.querySelector('playground-project'); |
| 20 | + projElem.config = { |
| 21 | + files: { |
| 22 | + 'index.js': { |
| 23 | + content: code, |
| 24 | + }, |
| 25 | + 'index.html': { |
| 26 | + content: `<!doctype html> |
| 27 | + <body> |
| 28 | + <canvas></canvas> |
| 29 | + <button type="button">Reset zoom</button> |
| 30 | + <script type="module" src="./index.js"></script> |
| 31 | + </body>`.replace('<', '<') |
| 32 | + , |
| 33 | + }, |
| 34 | + 'register.js': { |
| 35 | + content: registerBundle |
| 36 | + }, |
| 37 | + }, |
| 38 | + }; |
| 39 | +}) |
| 40 | +</script> |
0 commit comments