diff --git a/index.js b/index.js index 6b8887c..beaedd0 100644 --- a/index.js +++ b/index.js @@ -4,5 +4,6 @@ module.exports = { Line: require('./lib/line'), Pie: require('./lib/pie'), PolarArea: require('./lib/polar-area'), - Radar: require('./lib/radar') + Radar: require('./lib/radar'), + createClass: require('./lib/core').createClass }; diff --git a/lib/core.js b/lib/core.js index e116173..5cfa723 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1,5 +1,5 @@ module.exports = { - createClass: function(chartType, methodNames) { + createClass: function(chartType, methodNames, dataKey) { var classData = { displayName: chartType + 'Chart', getInitialState: function() { return {}; }, @@ -40,7 +40,8 @@ module.exports = { chart.destroy(); this.initializeChart(nextProps); } else { - updatePoints(nextProps, chart); + dataKey = dataKey || dataKeys[chart.name]; + updatePoints(nextProps, chart, dataKey); chart.update(); } }; @@ -82,7 +83,7 @@ var dataKeys = { 'Bar': 'bars' }; -var updatePoints = function(nextProps, chart) { +var updatePoints = function(nextProps, chart, dataKey) { var name = chart.name; if (name === 'PolarArea' || name === 'Pie' || name === 'Doughnut') { @@ -90,7 +91,6 @@ var updatePoints = function(nextProps, chart) { chart.segments[segmentIndex].value = segment.value; }); } else { - var dataKey = dataKeys[name]; nextProps.data.datasets.forEach(function(set, setIndex) { set.data.forEach(function(val, pointIndex) { chart.datasets[setIndex][dataKey][pointIndex].value = val;