简体   繁体   中英

React js and chart js pie chart type

Hello everyone i need to get a dynamic chart js pie type,

this is the request to get the data:

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

})

}

this the code with static data:

 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" },
           
           ]
        }]
      }

please what i should to do to get the dynamic value at my chart

Try using react-apexcharts. this lets you create dynamic charts as your wish

You should make new component with chart.js pie and define props , too. After receiving data from backend, you would import this component and send this data as props .

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM