Skip to content
This repository was archived by the owner on Jul 19, 2019. It is now read-only.

Commit 13fe5be

Browse files
committed
dynamically add data to chart
1 parent 30e77c8 commit 13fe5be

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

lib/core.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,21 @@ var updatePoints = function(nextProps, chart, dataKey) {
9494
} else {
9595
nextProps.data.datasets.forEach(function(set, setIndex) {
9696
set.data.forEach(function(val, pointIndex) {
97-
chart.datasets[setIndex][dataKey][pointIndex].value = val;
97+
if (typeof(chart.datasets[setIndex][dataKey][pointIndex]) == "undefined") {
98+
addData(nextProps, chart, setIndex, pointIndex);
99+
} else {
100+
chart.datasets[setIndex][dataKey][pointIndex].value = val;
101+
}
98102
});
99103
});
100104
}
101105
};
102106

103-
104-
107+
var addData = function(nextProps, chart, setIndex, pointIndex) {
108+
var values = [];
109+
nextProps.data.datasets.forEach(function(set) {
110+
values.push(set.data[pointIndex]);
111+
});
112+
chart.addData(values, nextProps.data.labels[setIndex]);
113+
};
105114

0 commit comments

Comments
 (0)