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

enable line chart to change it colors dynamically #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = {
updatePoints(nextProps, chart, dataKey);
if (chart.scale) {
chart.scale.xLabels = nextProps.data.labels;

if (chart.scale.calculateXLabelRotation){
chart.scale.calculateXLabelRotation();
}
Expand Down Expand Up @@ -127,11 +127,24 @@ var updatePoints = function(nextProps, chart, dataKey) {
chart.removeData();
}
nextProps.data.datasets.forEach(function(set, setIndex) {
// updating properties
Object.keys(set).forEach(function (prop) {
var val = set[prop];
if (prop === 'data') return; // skip data
chart.datasets[setIndex][prop] = val;
});

// updating points
set.data.forEach(function(val, pointIndex) {
if (typeof(chart.datasets[setIndex][dataKey][pointIndex]) == "undefined") {
addData(nextProps, chart, setIndex, pointIndex);
} else {
chart.datasets[setIndex][dataKey][pointIndex].value = val;
// update point color if available
if (set.pointColor) {
chart.datasets[setIndex][dataKey][pointIndex].fillColor = set.pointColor;
chart.datasets[setIndex][dataKey][pointIndex].highlightFill = set.pointColor;
}
}
});
});
Expand Down