2π
β
in js if you put a variable in an object without specifying the key it will take the name of the variable as the key. Chart.js expects a key data
for the data and not data2
so if you write your second config like so it will work:
const config_2 = {
type: 'bar',
data: data2,
options: {}
};
Live example to demonstrate issue:
const text = "hiii";
const data = {
text
};
const data2 = {
data: text
};
console.log(data);
console.log(data2);
Source:stackexchange.com