Reputation: 461
I am trying to draw a live bar chart using latest Chart.js alpha. I want to dynamically update both values and labels. However, when I try to address a specific bar, say, number 3:
$.each(my_chart.datasets, function(i, dataset){
dataset.data[3].fillColor = fc;
dataset.data[3].value = v;
});
I get a jQuery error, stating that I cannot get length of one of the parameters.
When I try to access the chart's dataset like this:
my_chart.datasets[0].data = new_values_array;
I get the TypeError: undefined is not an object
What is the right way to address this problem in the newest alpha? The examples suggest updating the whole array, but I can't see the difference between updating the whole array or addressing a specific element. Maybe I'm missing something. Thank you!
Upvotes: 0
Views: 1412
Reputation: 41075
You can update point by point, like so
$.each(my_chart.data.datasets, function (i, dataset) {
dataset.metaData[3].custom = {
backgroundColor: "green"
};
dataset.data[3] = 2.5;
});
my_chart.update();
Replace green
by fc
and 2.5
by v
Fiddle - https://jsfiddle.net/6qt14tpj/
Upvotes: 1