Giter VIP home page Giter VIP logo

adrianhajdin / project_corona_tracker Goto Github PK

View Code? Open in Web Editor NEW
1.4K 26.0 472.0 832 KB

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.

Home Page: https://covid19statswebsite.netlify.com/

HTML 3.86% JavaScript 87.11% CSS 9.03%
react reactjs react-project react-charts

project_corona_tracker's Introduction

COVID-19 Tracker

COVID-19 Tracker

Stay up to date with new projects

New major projects coming soon, subscribe to the mailing list to stay up to date https://resource.jsmasterypro.com/newsletter

Introduction

This is a code repository for the corresponding video tutorial.

In this video, we will create a full COVID-19 Tracker. We're going to use React, Charts.JS and Material UI.

By the end of this video, you will have a strong understanding of React's workflow and the use of hooks.

API used: https://covid19.mathdro.id/api

Setup:

  • run npm i && npm start

project_corona_tracker's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

project_corona_tracker's Issues

Invalid Date Found

Hi, I am getting invalid date on cards and also I found undefine in date buttom of line chart and also when i hover on the line chart.
That i am missing?

size of chart is too small

hey, so im tryying to implement this solution but i cant seem to figure out how to make the charts larger
here's chart.jsx

`import React, {useState, useEffect } from 'react';
import {fetchDailyData} from '../../api';
import { Line, Bar } from 'react-chartjs-2';

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

const Chart = ({data:{confirmed, recovered, deaths}, country}) => {
const [dailyData, setDailyData] =useState([]);

useEffect( () => {
	const fetchAPI = async () => {
		setDailyData(await fetchDailyData());
	}

	fetchAPI();
}, [])

const barChart = (
	confirmed
		? (
			<Bar 
			 	data = {{
					labels: ['Infetados','Recuperados','Mortes'],
					datasets: [{
						label: 'Pessoas',
						backgroundColor: [
							'rgba(0,0,255,0.5)',
							'rgba(0,255,0,0.5)',
							'rgba(255,0,0,0.5)',
						],
					data : [confirmed.value, recovered.value, deaths.value]
					}]
				 }}
				options= {{
					legend: {display: false},
					title: {display: true, text: `Estado atual em ${country}`},
				}}
			/>
		) : null
)

const lineChart = (
	dailyData.length
		? (
		<Line 
		data={{
			labels: dailyData.map(({ date })=> date),
			datasets: [ {
				data: dailyData.map(({confirmed})=>confirmed),
				label: 'Infetados',
				borderColor: '#3333ff',
				fill: true,
			}, {
				data: dailyData.map(({deaths}) => deaths),
				label: 'Mortos',
				borderColor: 'red',
				backgroundColor: 'red',
				fill: true,
			} ],
		}} 
	/>) : null
);

return (
	<div className={styles.container} >
		{country ? barChart : lineChart} 
	</div>
	)

}

export default Chart;`

here's Chart.module.css

.containter { display: flex; justify-content: center; width: 85%; }

hope you can help me , thanks for the amazing work man !

data not showing

Screenshot (6)

and line graph is not showing in starting time after sellecting country name it is showing bar graph only how to remove line graph

Sending fetchDailyData API response to Chart.jsx (using different API)

Hello! I am following through your tutorial on this tracker, but decided to use a different API as practice on consuming different kinds of datasets. I seem to have hit a wall though when it comes to handling data in fetchDailyData() in index.js, and also retrieving this data in a similar way as you to be used in the Line Chart.
I am using the following API path for fetchDailyData (global):https://corona.lmao.ninja/docs/?urls.primaryName=version%202.0.0#/JHUCSSE/get_v2_historical_all

My code is below:

index.js

export const fetchDailyData = async () => {


  try {
      const { data } = await axios.get(`${url}/historical/all`);
      
      
      const labels = Object.keys(data.cases);
      const cases = labels.map((name) => data.cases[name]);
      const deaths = labels.map((name) => data.deaths[name]);
      const recovered = labels.map((name) => data.recovered[name]);
      
      
      
      
  } catch (error) {
    return error;
    
  }
}

Chart.jsx

import React, {useState, useEffect} from 'react';

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

import {fetchDailyData} from '../../api';

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


const Chart = () => {
    const [dailyData, setDailyData]= useState([]);

    useEffect(() => {
        const fetchAPI = async () => {
             setDailyData(await fetchDailyData());
        }

        
        fetchAPI();
    });


    const lineChart = (
       <Line


        />
    );

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

        </div>
    );
};

export default Chart;

TypeError: countries.map is not a function

First of all let me thank you, for sharing this valuable knowledge
I coded along with you and everything went well for the first couple of minutes. However in the end Iยดm getting the following error:

TypeError: countries.map is not a function
19 | return (
20 |
21 | <NativeSelect defaultValue="" onChange={(e) => handleCountrychange(e.target.value)}>

22 | Global
| ^ 23 | {countries.map((country, i) => {country})}
24 |
25 |

TypeError: Cannot read property 'length' of undefined

I keep getting a TypeError: Cannot read property 'length' of undefined when I run the code. This is my Chart.js:
`import React, {useState, useEffect } from 'react';
import {fetchDailyData} from '../api'
import { Line, Bar } from 'react-chartjs-2';
import styles from './Chart.module.css';

const Chart = () => {
const [dailyData, setDailyData] = useState({});

useEffect (() => {
    const fetchAPI = async () => {
        setDailyData(await fetchDailyData());
    }
    
    fetchAPI();
}, []);

const lineChart = (
    dailyData.length
        ? (
        <Line 
        data={{
            labels: dailyData.map(({ date }) => date),
            datasets: [{
                data: dailyData.map(({ confirmed }) => confirmed),
                label: 'Infected',
                borderColor: '#3333ff',
                fill: true,
            }, {
                data: dailyData.map(({ deaths }) => deaths),
                label: 'Deaths',
                borderColor: 'red',
                backgroundColor: 'rgba(255, 0, 0, 0.5)',
                fill: true,
            }],
        }}
    />) : null
);

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

}

export default Chart;And here is my index.js:import axios from 'axios';

const url = 'https://covid19.mathdro.id/api'

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

    return {confirmed, recovered, deaths, lastUpdate};
} catch(error) {

}

}

export const fetchDailyData = async () => {
try {
const { data } = await axios.get('${url}/daily');

    const modifiedData = data.map((dailyData) => ({
        confirmed: dailyData.confirmed.total,
        deaths: dailyData.deaths.total,
        date: dailyData.reportDate,
    }));
    return modifiedData;
} catch(error) {

}

}`

unhandled Rejection (TypeError): Cannot read property 'length' of undefined

After working on fetchDailyData I am getting this error.
Screen Shot 2020-10-08 at 8 59 27 AM
React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
in Chart (at App.js:24)
in div (at App.js:22)
in App (at src/index.js:6)

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

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;```

dailyData returned empty array

Chart.jsx

import React, {useState, useEffect} from 'react';
import { fetchDailyData } from '../../api';
import { Line, Bar } from 'react-chartjs-2';
import styles from './Chart.module.css';

`
const Chart = () => {
const [dailyData, setDailyData] = useState([]);

useEffect(() => {
    const fetchApi = async () => {
        setDailyData(await fetchDailyData());
    }

    fetchApi();
});

console.log("dailyData: ", dailyData);

const lineChart = (
    dailyData.length
    ?  (   
        <Line  data={{
        labels: dailyData.map(({date}) => date), 
        datasets: [{
            data: dailyData.map(({ confirmed }) => confirmed),
            label: 'Infected',
            borderColor: '#3333fff',
            fill: true,
        },{
            data: dailyData.map(({ deaths }) => deaths),
            label: 'Deaths',
            borderColor: 'red',
            backgroundColor: 'rgba(255, 0, 0, 0.5)',
            fill: true,
        }]
    }} />) : null

);

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

}

export default Chart;
`

sss

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.