score:0

Accepted answer

modified my code to this and got the chart displayed. i don't know what the issue was but it could be that i hadn't added getcontext. i also created the ref outside my state.

class radarchart extends component {
constructor(props) {
    super(props);
}
chartref = react.createref();


componentdidmount () {
    const mychartref = this.chartref.current.getcontext("2d");
    new chart(mychartref, {
        type: 'radar',
        data: {
            labels: this.props.labels,
            datasets: [
                {
                    label: "my second dataset",
                    backgroundcolor: "rgba(26,179,148,0.2)",
                    bordercolor: "rgba(26,179,148,1)",
                    pointbackgroundcolor: "rgba(26,179,148,1)",
                    pointbordercolor: "rgba(26,179,148,1)",
                    data: this.props.data
                }
            ]
        },
        options: {
            responsive: true,
            legend: {
                display: false
            }
        }
    })
}

render() {
    return <canvas ref={this.chartref} />
}

}

Related Query

More Query from same tag