簡體   English   中英

React js和chart js餅圖類型

[英]React js and chart js pie chart type

大家好,我需要一個動態圖表js pie類型,

這是獲取數據的請求:

 async componentDidMount(){
    axios.get("http://localhost:8080/requete/tab1")
    .then(response => response.data)
    .then((data) =>{
      this.setState({dataL : data})

})

}

這是帶有 static 數據的代碼:

 const options = {
        animationEnabled: true,
        exportEnabled: true,
        theme: "light1", 
        title:{
          text: "Trip Expenses"
        },
        data: [{
          type: "pie",
          indexLabel: "{label}: {y}%",      
          startAngle: -90,
          dataPoints: [
            
            

            

            
            { y: 5, label: "Lost" },
            { y: 24, label: "Won" },
           
           ]
        }]
      }

請問我應該怎么做才能在我的圖表上獲得動態值

嘗試使用 react-apexcharts。 這使您可以根據需要創建動態圖表

您應該使用 chart.js 餅圖制作新組件並定義props 從后端接收數據后,您將導入此組件並將此數據作為props發送。

<Pie {...this.state.data} />

props: {
   data: Array,
   ....
}

computed() {
   pie() {
      return this.data || [];
   }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM