如何更新Chartjs中的注释值3.7.1
找到了一堆旧帖子,但在较新版本上找不到任何东西。我正在使用ChartJS 3.7.1和Chartjs-Plugin-nototation 1.4.0
我可以通过以下方式添加新的注释:
myChart.options.plugins.annotation.annotations['newAnnotation'] = {
type: 'line',
xMin: 0,
xMax: 11,
yMin: 200000,
yMax: 200000,
borderColor: 'rgb(255, 99, 132)',
borderWidth: 2
};
myChart.update();
但是如何动态访问现有注释以便以后更改值?
尝试这样的事情不起作用:
myChart.options.plugins.annotation.annotations[0].value = 200000;
Found a bunch of old posts but couldn't find anything on the newer versions. I'm using Chartjs 3.7.1 and chartjs-plugin-annotation 1.4.0
I can add a new annotation via:
myChart.options.plugins.annotation.annotations['newAnnotation'] = {
type: 'line',
xMin: 0,
xMax: 11,
yMin: 200000,
yMax: 200000,
borderColor: 'rgb(255, 99, 132)',
borderWidth: 2
};
myChart.update();
but how do I access the the existing annotation dynamically in order to change the value afterwards?
Trying something like this didn't work:
myChart.options.plugins.annotation.annotations[0].value = 200000;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以如下完成:
请查看下面的可运行代码。要查看其工作原理,请在
INPUT
元素上键入图表顶部,然后按 EnterThis can be done as follows:
Please take a look at the runnable code below. To see how it works, type a new y-value into the
input
element top of the chart and press Enter