gpt4 book ai didi

javascript - 向图表添加垂直线

转载 作者:行者123 更新时间:2023-12-03 00:18:08 25 4
gpt4 key购买 nike

我正在使用 Chartkick 和 Chart.js 来渲染一些折线图。现在我正在尝试添加一条垂直线来显示用户输入的注释,但我似乎无法让注释插件工作。

<line-chart width="80vw" :dataset="dataset" :library="chartOptions" class="animated slideInRight delay-0.01s" v-else :data="photon.data.tempF" ytitle="Temperature F" :colors="['#ff0000']" :download="true"></line-chart>





chartOptions: {
annotation: {
annotations: [
{
type: "line",
mode: "vertical",
scaleID: "x-axis-0",
value: "Wed Jan 23 2019 10:31:27 GMT-0500 (Eastern Standard Time)",
borderColor: "red",
label: {
content: "TODAY",
enabled: true,
position: "top"
}
}
]
},
tooltips: {
callbacks: {
label: function (tooltipItem, data) {
console.log(data.labels[tooltipItem.index])
console.log(tooltipItem)
return [data.datasets[0].data[tooltipItem.index],data.labels[tooltipItem.index]]
}
}
},
height: '400px',
pan: {
enabled: false,
mode: 'xy',
},
zoom: {
enabled: true,
mode: 'x',
},
drag: true,
gridLines: {
zeroLineColor: "rgba(0,255,0,1)"
},
},```


最佳答案

它没有绘制注释的原因是因为在我的 main.js 中我没有导入或注册它

import ChartAnnotationsPlugin from 'chartjs-plugin-annotation'
Chart.plugins.register(ChartAnnotationsPlugin)

关于javascript - 向图表添加垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54449104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com