reactjs / react-chartjs

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

DoughnutChart no longer rendering when accessing this.props in parent component #40

Open dennisjac opened 9 years ago

dennisjac commented 9 years ago

Something really strange is happening when I try to build data dynamically for a DoughnutChart. Consider the following render function:

    render: function(){
        var piedata = [];
        var x = 1;
        if (x > 0) {
        //if (this.props.stats.stats.minions.outdated > 0) {
            console.log('value = '+this.props.stats.stats.minions.outdated);
            piedata = [{
              value: 14,
              color: "#FDB45C",
              highlight: "#FFC870",
              label: "Failed"
            }];
        }

        return <DoughnutChart data={piedata} width="600" height="250"/>;
    }

Notice the two if lines with one of them commented out. When run like this the DoughnutChart is rendered as expected. Now comment the "if (x > 0) {" line and uncomment the other if line. Suddenly the chart no longer renders with an error of "TypeError: chart.segments[segmentIndex] is undefined".

What is really strange though is that the output of the console.log() line is "value = 1" so the if condition evaluates to true and the same code as before is executed. I also added some debug code that outputs the content of "piechart" just before the return statement and in both cases it is the same (a list with one element). I have no clue what is going on here. Since in both cases the exact same input data is provided for "piedata" the result should be the same but it isn't. Any ideas what might be going on here?

flccrakers commented 8 years ago

I have no idea at all and would like to know what's the problem here. I have the same kind and don't know how to fix it…