reactjs / react-chartjs

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

Chart not rendering on receiving new props #37

Closed aakrem closed 8 years ago

aakrem commented 9 years ago
var DoughnutChart = require('react-chartjs').Doughnut;

var Statistics = React.createClass({
    render: function () {
        var foo = this.props.foo;
        data = [
            {
                value: foo.foo.length,
                color: '#3EBBD0',
                highlight: '#FF5A5E',
                label: 'foo'
            },
            {
                value: foo.bar.length,
                color: '#65D047',
                highlight: '#5AD3D1',
                label: 'bar'
            },
            {
                value: foo.foobar.length,
                color: '#D07054',
                highlight: '#FFC870',
                label: 'foobar'
            },
        ];

        return (
            <div id="statistics">
                <DoughnutChart data={data} options={chartOptions}/>
            </div>
        );
    }
});
aakrem commented 8 years ago

redraw works thanks solution <DoughnutChart data={chartData} options={chartOptions} redraw/>

Dallas62 commented 8 years ago

Sorry, just working on the same issue, but redraw is ugly with the animation.

Just find that if the total of all value is 0 the chart do not update. (Seems to come from ChartJS)

I just not render the DoughnutChart when total = 0, and render the Chart when it's ok.