chart.js中多个图表上的工具提示显示错误的值 [英] Tooltips on multiple charts in chart.js showing the wrong values

查看:58
本文介绍了chart.js中多个图表上的工具提示显示错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用最新的Chart.bundle.js在同一页面上创建多个堆叠条形图。例如,我有3个包含2个数据集的图表。图表是正确的,但每个图表上的工具提示始终相同并显示错误的值。 截图链接。所有的值都是零,这显然是错误的。

I am using latest Chart.bundle.js to create multiple stacked Bar charts on same page. For example, I have 3 charts with 2 datasets. Charts are correct, but tooltips on each of the charts are always the same and showing wrong values. screenshot link. All the values are zero, which is obviously wrong.

工具提示模式是索引,每个图表的画布都有不同的id,数据集变量都是不同的。

Tooltips mode is index, canvas for each chart has different id, dataset variables are all different.

推荐答案

我的解决方案与@ queen-juliet的答案有些相似。

My solution was somewhat similar to the @queen-juliet's answer.

我有共享配置变量,其中数据键在循环内添加和更新。尽管我在页面上显示的多个chart.js对象显示的是正确的数据,但工具提示仅显示在一个(随机)图表上。解决方案是在我的循环中声明并填充整个配置。

I had a shared config variable with the data key being added and updated within a loop. Even though the multiple chart.js objects I had on the page were showing the correct data, the tooltips were shown on one (random) chart only. The solution was to declare and fill the whole config inside my loop instead.

这篇关于chart.js中多个图表上的工具提示显示错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆