Update Dataset by Label name #10222
Answered
by
LeeLenaleee
ImJustBull
asked this question in
Q&A
-
Hello Guys is there a way to Update the dataset by the Label name |
Beta Was this translation helpful? Give feedback.
Answered by
LeeLenaleee
Mar 8, 2022
Replies: 1 comment
-
You can use the const options = {
type: 'line',
data: {
labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3, 5, 2, 3],
borderColor: 'pink'
},
{
label: '# of Points',
data: [7, 11, 5, 8, 3, 7],
borderColor: 'orange'
}
]
},
options: {}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
const chart = new Chart(ctx, options);
setTimeout(() => {
chart.data.datasets.find(e => e.label === '# of Points').data[0] = 50;
chart.update();
}, 1000) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
ImJustBull
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can use the
find
method to get the correct dataset by comparing the label. Then you can update it: