Trying to publish my code on jsfiddle, I managed to find a solution to this very strange problem. I had
var barCharData = { labels: ["2", "3", "4"], datasets: [] };
therefore, in the beginning there is no data in any of my diagrams (before receiving data from the database). For each graph, I did something like this:
for(var i=1; i <= number_of_charts; i++){ bar_char_data_array.push(barChartData); var myBar = new Chart(ctx, { type: 'bar', data: bar_char_data_array[i-1], options: { tooltips: { mode: 'label', intersect: true } } }); }
It turned out that javascript considers each element of the array "bar_char_data_array" as the same object and changes the data for one of the diagrams, which leads to a change in the data for the rest. I still donβt know why all the diagrams were correct until I hovered to see a hint. However, the solution to my problem was to remove the barChartData variable.
for(var i=1; i <= number_of_charts; i++){ bar_char_data_array.push({ labels: ["2", "3", "4"], datasets: [] }); var myBar = new Chart(ctx, { type: 'bar', data: bar_char_data_array[i-1], options: { tooltips: { mode: 'label', intersect: true } } }); }
source share