Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue May 7, 2020 · 2 comments

Comments

@mayanksinha9
Copy link

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
Copy link
Author

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){

}

}``

@mayanksinha9 mayanksinha9 changed the title chart is not displaying api data chart is not displaying api data. i am using this api : https://api.apify.com/v2/key-value-stores/toDWvRj1JpTXiM8FF/records/LATEST?disableRedirect=true May 7, 2020
@Suryakumar007
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants