第 3:13 行:'zoom' 已定义,但在 React.js 中使用 Chartjs-2 时从未使用过 no-unused-vars'

Line 3:13: 'zoom' is defined but never used no-unused-vars' while using Chartjs-2 in React.js

我正在使用 react-chartjs-2 在 React.js 中制作折线图。我正在使用缩放和平移选项。我从 react-chartjs-2 导入了 zoom 并稍后在我的代码中使用了它。注意:如果我删除此导入行,图表中的缩放功能将停止工作:

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

         <Line
            data={data}
            options={{
                title: {
                    display: true,
                    text: `${data.title}`,
                    fontSize: 20
                },
                legend: {
                    display: true,
                    position: 'right'
                },
                scales: {
                    yAxes: [{
                        ticks: {
                            beginAtZero: true
                        }
                    }]
                },
                pan: {
                    enabled: true,
                    mode: 'x',
                    rangeMin: {
                        x: 20,
                        y: 20
                    },
                    rangeMax: { 
                        x: 40,
                        y: 40
                    },
                    speed: 0.5
                },
                zoom: {
                    enabled: true,
                    mode: 'x',
                    rangeMin: {
                        x: 15,
                        y: 10
                    },
                    rangeMax: { 
                        x: 20,
                        y: 20
                    },
                    speed: 0.5
                }
            }}
        />

但仍然出现此错误:

./src/components/LineGraph.jsx Line 3:13: 'zoom' is defined but never used no-unused-vars

您的代码没有使用导入的缩放。您有一个带有名为 zoom 的键的对象,但您没有在任何地方使用导入的 zoom 变量。

尝试 import 'chartjs-plugin-zoom'; 而不是 import * as zoom from 'chartjs-plugin-zoom';,因为您只想加载模块,而不是引用它。