For those who worked on the voting app project, did any of you use chart js? I’ve followed the documentation to the letter, and I’m getting the error:
Uncaught (in promise) TypeError: Cannot read property ‘length’ of null
at acquireContext (bundle.js:65850)
at new Chart.Controller (bundle.js:65903)
at new Chart (bundle.js:62577)
at ChartVisual.render (bundle.js:89186)
And this is my code: (I intentionally left out the return content for the sake of brevity, but it contains the required canvas element to be passed in to the constructor.)
const colors = ["#ff0000", "#ffff00", "#ffa500", "#008000", "#800080", "#ff00ff", "#0000ff", "#9acd32", "#00ff00", "#00ced1", "#d2691e"];
const data = {
labels: this.props.choices,
datasets: [{
data: this.props.chartData,
backgroundColor: chartColors,
hoverBackgroundColor: chartColors
}]
}
let chartColors = colors.slice(0, this.props.choices.length);
let ctx = document.getElementById("dataChart");
let chart = new Chart(ctx, {
type: "doughnut",
data: data
});