Data visualization in ReactJs with ChartJs

前端 未结 1 1507
我寻月下人不归
我寻月下人不归 2021-01-17 03:09

I am new in reactjs. Currently I\'m developing an app which shows json COVID-19 api data into visualization using chartjs. I tried this from yesterday but I can\'t show the

1条回答
  •  再見小時候
    2021-01-17 04:05

    Looks like data property within dataset takes only array of numbers. I have simplifies your code using class based component. It will help you get started.

    https://codesandbox.io/s/react-chartjs-2-example-mzh9o

     setChartData = () => {
        let { data } = this.state;
        let chartData = {
          labels: ["Cases", "Deaths", "Recovered"],
          datasets: [
            {
              label: "cases",
              data: Object.values(data.cases)
            },
            {
              label: "deaths",
              data: Object.values(data.deaths)
            },
            {
              label: "recovered",
              data: Object.values(data.recovered)
            }
          ]
        };
        this.setState({
          chart: chartData
        });
      };
    
    

    0 讨论(0)
提交回复
热议问题