diff --git a/frontend/src/components/Charts/BarChart.tsx b/frontend/src/components/Charts/BarChart.tsx index aaf90c8..9823ebf 100644 --- a/frontend/src/components/Charts/BarChart.tsx +++ b/frontend/src/components/Charts/BarChart.tsx @@ -1,6 +1,7 @@ import { ApexOptions } from 'apexcharts'; -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import ReactApexChart from 'react-apexcharts'; +import { fetchWeatherDataList } from '../../api/WeatherData'; const options: ApexOptions = { colors: ['#3C50E0', '#80CAEE'], @@ -43,9 +44,6 @@ const options: ApexOptions = { enabled: false, }, - xaxis: { - categories: ['M', 'T', 'W', 'T', 'F', 'S', 'S'], - }, legend: { position: 'top', horizontalAlign: 'left', @@ -74,21 +72,36 @@ const ChartTwo: React.FC = () => { series: [ { name: 'PM 2.5', - data: [44, 55, 41, 67, 22, 43, 65], + data: [], }, { name: 'PM 10', - data: [13, 23, 20, 8, 13, 27, 15], + data: [], }, ], }); - const handleReset = () => { - setState((prevState) => ({ - ...prevState, - })); - }; - handleReset; + useEffect(() => { + const fetchData = async () => { + try { + const weatherData = await fetchWeatherDataList(7); + + const pm25Data = weatherData?.map((data) => data.outdoor_pm25) || []; + const pm10Data = weatherData?.map((data) => data.outdoor_pm10) || []; + + setState({ + series: [ + { name: 'PM 2.5', data: pm25Data }, + { name: 'PM 10', data: pm10Data }, + ], + }); + } catch (error) { + console.error('Error fetching weather data:', error); + } + }; + + fetchData(); + }, []); return (
@@ -98,42 +111,6 @@ const ChartTwo: React.FC = () => { Air Quality
-
-
- - - - - - - -
-