我正在努力设置chartjs-plugin-crosshair来处理我的图表(chartjs)。
项目依赖关系包括:
- 路线图:4.1.0
- chartjs-插件-十字准线:1.2.0
- Chart.js:3.7.1
我得到错误:
**第一个:**未捕获的类型错误:无法读取未定义的属性(阅读'dragStarted')
**然后(当鼠标移到图表上时):**未捕获TypeError:无法读取未定义的属性(阅读'length')
我的元件:
<template>
<Line :chart-data="chartData" :plugins="[CrosshairPlugin]" :chart-options="chartOptions" ref="myChart" />
</template
<script setup>
import { Line } from 'vue-chartjs'
import { Chart as ChartJS, Title, Tooltip, Legend, PointElement, LineElement, CategoryScale, LinearScale, TimeSeriesScale } from 'chart.js'
import {CrosshairPlugin,Interpolate} from 'chartjs-plugin-crosshair';
ChartJS.register(Title, Tooltip, Legend, PointElement, LineElement, CategoryScale, LinearScale, TimeSeriesScale)
const myChart = ref();
const chartData ={
labels: [1,2,3,4],
datasets: [{label:'test', data:[51,52,53,54],borderWidth:1, borderColor:'#f0f'}]
}
const chartOptions = {
interaction: {
mode: 'nearest'
},
scales: {
xAxes: {
stacked:true,
grid: {
color:"rgba(80,201,209,.3)",
borderColor:"rgba(80,201,209,1)"
},
title: {
display:true,
text: 'value'
},
ticks: {
color:"rgba(80,201,209,1)"
source: 'labels',
},
},
yAxes: {
grid: {
color:"rgba(80,201,209,.3)",
borderColor:"rgba(80,201,209,1)"
},
title: {
display: false,
},
ticks: {
color:rgba(80,201,209,1),
},
},
},
plugins: {
crosshair:
{
sync: {
enabled: false
},
zoom: {
enabled: false
},
snap: {
enabled: true
}
}
}
}
有谁能帮忙吗?
1条答案
按热度按时间ymzxtsji1#
这是因为您为秤提供了一个自定义ID,将其设置回默认的
x
和y
(通过将对象键从yAxes
更改为y
,并从xAxes
更改为x
)将解决您的问题:第一个