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

size of chart is too small #27

Open
tduraes opened this issue Dec 15, 2020 · 1 comment · May be fixed by #61
Open

size of chart is too small #27

tduraes opened this issue Dec 15, 2020 · 1 comment · May be fixed by #61

Comments

@tduraes
Copy link

tduraes commented Dec 15, 2020

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 !

@hitvaghani26
Copy link

I found that we have to give inline CSS I don't know why but it works.
change scr/chart/Chart.jsx in line 74 (return statement)
return ( <div className={styles.container} style={{ width: '100%' }}> {country ? barChart : lineChart} </div> ); };

image

I hope it will work for you>

@SaayanBiswas98 SaayanBiswas98 linked a pull request Oct 3, 2023 that will close this issue
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

Successfully merging a pull request may close this issue.

2 participants