reactjs / react-chartjs

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

Excanvas polyfill workflow #69

Closed Joran182to closed 8 years ago

Joran182to commented 8 years ago

Hi, I liked chart.js lib and wanted to use it in my React-based app, but I need to support IE8. So, I decided to use excanvas polyfill. It's not a problem to use it with chart.js itself, so it working like this in my app: Rendering empty canvas:

    render() {
        return (
            <canvas ref="canvas" width="700" height="400"/>
        );
    }

And then initializing excanvas (which is loaded only in IE8 by conditional tags) and rendering chart into empty canvas:

    componentDidMount() {
        if (typeof G_vmlCanvasManager !== 'undefined') {
            G_vmlCanvasManager.initElement(this.refs.canvas);
            options.animation = false;
        }
        let ctx = this.refs.canvas.getContext("2d");
        let myLineChart = new Chart(ctx).Line(data, options);
    }

But chart components from react-chartjs creating canvas elements by itself, so I didn't found a way to initialize an excanvas polyfill. Is it possible to use excanvas with react-chartjs or I should use just a chart.js like now?

austinpray commented 8 years ago

Will accept PRs for this.