我正在嘗試使用 react-chartjs-2 制作條形圖。每當我使用以下代碼運行我的反應應用程式時,它只顯示一個黑頁。我在這里做錯了什么。這是我的 Chart.js 代碼
import React,{Component} from "react";
import { Bar } from 'react-chartjs-2';
class Chart extends Component{
constructor(props){
super(props);
this.state = {
chartData:{
labels: ['Boston','Worcestor',
'Springfield','Lowell','Cambridge','New bedford'],
datasets: [
{
label: 'Population',
data: [
641712,147895,12479546,1457897,127955,98745
],
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)',
'rgba(255, 99, 131, 0.2)'
]
}
]
}
}
}
render(){
return(
<div className="chart">
<Bar
data={this.state.chartData}
options={{
maintainAspectRatio: false
}}
/>
</div>
)
}
}
export default Chart;

uj5u.com熱心網友回復:
您需要將此行添加到您的匯入中: import Chart from 'chart.js/auto';
請參閱Chart.js 集成
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/415754.html
標籤:
上一篇:如何通過批處理腳本從TXT檔案的最后一行提取最后一個單詞
下一篇:如何更改Gradle版本。幫我
