reactjs / react-chartjs

common react charting components using chart.js
MIT License
2.93k stars 301 forks source link

Pie chart woes #41

Closed tquetano-r7 closed 8 years ago

tquetano-r7 commented 8 years ago

Having issue with Pie charts. I'm passing in data with a basic format:

var data = [
    {color:"blue", label:"test1",value:1},
    {color:"red", label:"test2", value:2}
];

var options = {
    animateRotate:true
}

And calling it as such:

<PieChart data={data} options={options}/>

And get the error "cannot assign value on undefined" on:

if (name === 'PolarArea' || name === 'Pie' || name === 'Doughnut') {
    nextProps.data.forEach(function(segment, segmentIndex) {
        chart.segments[segmentIndex].value = segment.value; // right here
    });
}

I've checked, the segmentIndex is correctly showing as 0. Is there something I'm missing?

tquetano-r7 commented 8 years ago

Quick update ... I've "fixed" the problem by only rendering the chart if there is data. It appears that when an empty data array is passed it blows up, so I have a simple if / else in the render to just show a default. While this works now, I feel like there should be something that exits without error.