我試圖添加一個條形圖到我的應用程序與現在的任意數據,但我無法得到它呈現。它的輸入正確,我使用了chart.js網站的示例代碼,但沒有運氣。我錯過了什麼?爲什麼此條形圖使用chart.js不在react.js中呈現?
import Chart from 'chart.js';
import React, { Component } from 'react';
class ChartTeamOne extends Component {
setState(){
const t1ChartEl= document.getElementById("teamOneCanvas");
let teamOneChart = new Chart(t1ChartEl,{
type: 'bar',
data: {
labels: ["Red", "Blue"],
datasets: [{
label: '# of Votes',
data: [12, 19],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
],
borderColor: [
'rgba(255,99,132,1)',
'rgba(54, 162, 235, 1)',
],
borderWidth: 1
}]
},
options: {
scales: {
yAxes: [{
ticks: {
beginAtZero:true
}
}]
}
}
});
}
render(){
return(
<canvas id="teamOneCanvas"></canvas>
);
}
}
export default ChartTeamOne;