如何正确实现十字线插件与vue chartjs?-保持获取无法读取未定义错误的属性(阅读'dragStarted')

rryofs0p  于 2022-11-06  发布在  Chart.js
关注(0)|答案(1)|浏览(237)

我正在努力设置chartjs-plugin-crosshair来处理我的图表(chartjs)。
项目依赖关系包括:

  • 路线图:4.1.0
  • chartjs-插件-十字准线:1.2.0
  • Chart.js:3.7.1

我得到错误:

**第一个:**未捕获的类型错误:无法读取未定义的属性(阅读'dragStarted')
**然后(当鼠标移到图表上时):**未捕获TypeError:无法读取未定义的属性(阅读'length')

我的元件:

  1. <template>
  2. <Line :chart-data="chartData" :plugins="[CrosshairPlugin]" :chart-options="chartOptions" ref="myChart" />
  3. </template
  4. <script setup>
  5. import { Line } from 'vue-chartjs'
  6. import { Chart as ChartJS, Title, Tooltip, Legend, PointElement, LineElement, CategoryScale, LinearScale, TimeSeriesScale } from 'chart.js'
  7. import {CrosshairPlugin,Interpolate} from 'chartjs-plugin-crosshair';
  8. ChartJS.register(Title, Tooltip, Legend, PointElement, LineElement, CategoryScale, LinearScale, TimeSeriesScale)
  9. const myChart = ref();
  10. const chartData ={
  11. labels: [1,2,3,4],
  12. datasets: [{label:'test', data:[51,52,53,54],borderWidth:1, borderColor:'#f0f'}]
  13. }
  14. const chartOptions = {
  15. interaction: {
  16. mode: 'nearest'
  17. },
  18. scales: {
  19. xAxes: {
  20. stacked:true,
  21. grid: {
  22. color:"rgba(80,201,209,.3)",
  23. borderColor:"rgba(80,201,209,1)"
  24. },
  25. title: {
  26. display:true,
  27. text: 'value'
  28. },
  29. ticks: {
  30. color:"rgba(80,201,209,1)"
  31. source: 'labels',
  32. },
  33. },
  34. yAxes: {
  35. grid: {
  36. color:"rgba(80,201,209,.3)",
  37. borderColor:"rgba(80,201,209,1)"
  38. },
  39. title: {
  40. display: false,
  41. },
  42. ticks: {
  43. color:rgba(80,201,209,1),
  44. },
  45. },
  46. },
  47. plugins: {
  48. crosshair:
  49. {
  50. sync: {
  51. enabled: false
  52. },
  53. zoom: {
  54. enabled: false
  55. },
  56. snap: {
  57. enabled: true
  58. }
  59. }
  60. }
  61. }

有谁能帮忙吗?

ymzxtsji

ymzxtsji1#

这是因为您为秤提供了一个自定义ID,将其设置回默认的xy(通过将对象键从yAxes更改为y,并从xAxes更改为x)将解决您的问题:
第一个

相关问题