adrianhajdin / project_corona_tracker

This is a code repository for the corresponding YouTube video. In this tutorial, we are going to build and deploy a corona tracker application. Covered topics: React.js, Chart.js, Material UI, and much more.
https://covid19statswebsite.netlify.com/
1.47k stars 485 forks source link

chart is not displaying api data. i am using this api : https://api.apify.com/v2/key-value-stores/toDWvRj1JpTXiM8FF/records/LATEST?disableRedirect=true #8

Open mayanksinha9 opened 4 years ago

mayanksinha9 commented 4 years ago

import React,{useState,useEffect} from 'react'; import { fetchRegionData } from '../../api';

import {Line,Bar} from 'react-chartjs-2';

import styles from './Chart.module.css';

const Chart=()=>{ const[regionData,setRegionData]=useState([]);

useEffect(()=>{
    const fetchAPI=async()=>{
        setRegionData(await fetchRegionData());
    }

    console.log(regionData);

    fetchAPI();
});

const lineChart=( ( <Line data={{ labels: regionData && regionData.map(({region})=>region), datasets:[{ data: regionData&&regionData.map(({totalInfected})=>totalInfected), label:'Infected', borderColor:'#3333ff', fill:true, },{ data: regionData&&regionData.map(({recovered})=>recovered), label:'Recovered', borderColor:'green', fill:true, },{ data: regionData&&regionData.map(({deceased})=>deceased), label:'Deaths', borderColor:'red', fill:true, }], }} />) );

return(
    <div className={styles.container} >
        {lineChart}
    </div>
)

}

export default `Chart;```

mayanksinha9 commented 4 years ago

import axios from 'axios';

const url='https://api.apify.com/v2/key-value-stores/toDWvRj1JpTXiM8FF/records/LATEST?disableRedirect=true';

export const fetchData=async()=>{ try{ const {data:{activeCases,recovered,deaths,lastUpdatedAtApify}}= await axios.get(url);

return {activeCases,recovered,deaths,lastUpdatedAtApify};
}
catch(error){

}

}

export const fetchRegionData= async()=>{ try{ const{data}=await axios.get(${url}/regionData); const modifiedData=data.map((regionData)=>({ totalInfected:regionData.totalInfected, recovered:regionData.recovered, deceased:regionData.deceased, }));

return modifiedData; }

catch(error){

}

}``

Suryakumar007 commented 4 years ago

Hi, kindly provide a github link to your code or the error information so that we can identify where it is breaking.