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

2022-01-22 00:00:00 charts javascript chart.js

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.

解决方案

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.

相关文章