chart.js 中多个图表上的工具提示显示错误的值多个、图表、错误、提示

2023-09-08 09:03:33 作者:怡人清欢

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.

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

解决方案 35款值得网站开发者收藏的JS图形图表库

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

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.