Commit 840c7c7a authored by Spark's avatar Spark
Browse files

chart 분리

parent 060d5f35
......@@ -6,46 +6,7 @@ import { callUserInfo } from '../utils/CheckDB';
import { routesClient } from './../routesClient';
import { isLogined } from './../utils/Auth';
function ChartHumidity() {
const [humi, setHumi] = useState([])
const [newLabel, setNewLabel] = useState([])
useEffect(() => {
if (isLogined()) {
axios.get(routesClient.userWeather, { withCredentials: true })
.then((res) => {
console.log('humi', res.data.contents.weather_in)
const userWeather = res.data.contents.weather_in
const Array = []
const Array2 = []
for (let i = 0; i < userWeather.length; i++) {
Array.push(userWeather[i].humi)
Array2.push(userWeather[i].collected_at.split('T')[1].split('.')[0])
}
setHumi(Array)
setNewLabel(Array2)
})
}
else {
axios.get(routesClient.outsideLoc + `3743011`)
.then((res) => {
const outWeather = res.data.contents.weather_out
const Array = []
const Array2 = []
for (let i = 0; i < outWeather.length; i++) {
Array.push(outWeather[i].humi)
Array2.push(outWeather[i].collected_at.split('T')[1].split('.')[0])
// const colHour = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[0]
// const colMin = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[1]
}
setHumi(Array)
setNewLabel(Array2)
})
}
}, [])
function ChartHumidity({humi, newLabel}) {
const options = {
legend: {
......
......@@ -6,45 +6,7 @@ import { callUserInfo } from '../utils/CheckDB';
import { isLogined } from './../utils/Auth';
import { routesClient } from './../routesClient';
function ChartPressure() {
const [press, setPress] = useState([])
const [newLabel, setNewLabel] = useState([])
useEffect(() => {
if (isLogined()) {
axios.get(routesClient.userWeather, { withCredentials: true })
.then((res) => {
console.log('press', res.data.contents)
const userWeather = res.data.contents.weather_in
const Array = []
const Array2 = []
for (let i = 0; i < userWeather.length; i++) {
Array.push(userWeather[i].press)
Array2.push(userWeather[i].collected_at.split('T')[1].split('.')[0])
}
setPress(Array)
setNewLabel(Array2)
})
}
else {
axios.get(routesClient.outsideLoc + `3743011`)
.then((res) => {
const outWeather = res.data.contents.weather_out
const Array = []
const Array2 = []
for (let i = 0; i < outWeather.length; i++) {
Array.push(outWeather[i].press)
Array2.push(outWeather[i].collected_at.split('T')[1].split('.')[0])
// const colHour = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[0]
// const colMin = outWeather[i].collected_at.split('T')[1].split('.')[0].split(':')[1]
}
setPress(Array)
setNewLabel(Array2)
})
}
}, [])
function ChartPressure({press, newLabel}) {
const options = {
legend: {
......
import { useState } from "react";
import { useEffect, useState } from "react";
import { Card, Row, Tab, Tabs } from "react-bootstrap";
import ChartTemp from './ChartTemp';
import ChartHumidity from './ChartHumidity';
import ChartWindSpeed from './ChartWindSpeed';
import ChartPressure from './ChartPressure';
import '../App.css'
import { getWeatherOut } from './../utils/CheckDB';
import { isLogined } from './../utils/Auth';
import axios from "axios";
import { routesClient } from './../routesClient';
function ChartTabs() {
......@@ -23,6 +24,87 @@ function ChartTabs() {
}
const [temp, setTemp] = useState([]);
const [press, setPress] = useState([]);
const [humi, setHumi] = useState([])
const [windSpd, setWindSpd] = useState([])
const [newLabel, setNewLabel] = useState([]);
const [tempNewLabel, setTempNewLabel] = useState([]);
useEffect(() => {
if (isLogined()) {
axios.get(routesClient.userWeather, { withCredentials: true })
.then((res) => {
console.log(res.data.contents.weather_in)
const userWeather = res.data.contents.weather_in
const userWeatherPredict = res.data.contents.weather_predict
const tempArray = []
const humiArray = []
const pressArray = []
const windspeedArray = []
const tempLabelArray = []
const labelArray = []
for (let i = 3; i < 9; i++) {
tempArray.push(userWeather[i].temp)
humiArray.push(userWeather[i].humi)
pressArray.push(userWeather[i].press)
windspeedArray.push(userWeather[i].wind_speed)
tempLabelArray.push(userWeather[i].collected_at.split('T')[1].split('.')[0])
labelArray.push(userWeather[i].collected_at.split('T')[1].split('.')[0])
}
for (let j = 0; j < 3; j++) {
tempArray.push(userWeatherPredict[j].temp)
tempLabelArray.push(userWeatherPredict[j].collected_at.split('T')[1].split('.')[0])
}
setTemp(tempArray)
setHumi(humiArray)
setPress(pressArray)
setWindSpd(windspeedArray)
setTempNewLabel(tempLabelArray)
setNewLabel(labelArray)
})
}
else {
axios.get(routesClient.outsideLoc + `3743011`).then((res) => {
const outWeather = res.data.contents.weather_out;
const tempArray = []
const humiArray = []
const pressArray = []
const windspeedArray = []
const tempLabelArray = []
const labelArray = []
let i = outWeather.length - 9;
for (i; i < outWeather.length; i++) {
tempArray.push(outWeather[i].temp)
humiArray.push(outWeather[i].humi)
pressArray.push(outWeather[i].press)
windspeedArray.push(outWeather[i].wind_speed)
tempLabelArray.push(outWeather[i].collected_at.split("T")[1].split(".")[0]);
labelArray.push(outWeather[i].collected_at.split("T")[1].split(".")[0]);
}
setTemp(tempArray)
setHumi(humiArray)
setPress(pressArray)
setWindSpd(windspeedArray)
setTempNewLabel(tempLabelArray);
setNewLabel(labelArray);
});
}
}, []);
//3743011 default
......@@ -36,16 +118,16 @@ function ChartTabs() {
onSelect={(k) => setKey(k)}
className="mb-3" >
<Tab eventKey="temp" title="온도">
<ChartTemp />
<ChartTemp temp={temp} newLabel={tempNewLabel} />
</Tab>
<Tab eventKey="humidity" title="습도">
<ChartHumidity />
<ChartHumidity humi={humi} newLabel={newLabel} />
</Tab>
<Tab eventKey="windspeed" title="풍속">
<ChartWindSpeed />
<ChartWindSpeed windSpd={windSpd} newLabel={newLabel} />
</Tab>
<Tab eventKey="pressure" title="기압">
<ChartPressure />
<ChartPressure press={press} newLabel={newLabel} />
</Tab>
</Tabs>
</Card>
......
import React, { useState } from "react";
import React from "react";
import { Col } from "react-bootstrap";
import { Bar } from "react-chartjs-2";
import { callUserInfo, getWeather } from "../utils/CheckDB";
import { useEffect } from "react";
import axios from "axios";
import { routesClient } from "./../routesClient";
import { isLogined } from "./../utils/Auth";
function ChartTemp() {
const [temp, setTemp] = useState([]);
const [newLabel, setNewLabel] = useState([]);
useEffect(() => {
if (isLogined()) {
axios.get(routesClient.userWeather, { withCredentials: true })
.then((res) => {
console.log('temp', res.data.contents)
const userWeather = res.data.contents.weather_in
const userWeatherPredict = res.data.contents.weather_predict
const Array = []
const Array2 = []
for (let i = 3; i < 9; i++) {
Array.push(userWeather[i].temp)
Array2.push(userWeather[i].collected_at.split('T')[1].split('.')[0])
}
for (let j = 0; j < 3; j++) {
Array.push(userWeatherPredict[j].temp)
Array2.push(userWeatherPredict[j].collected_at.split('T')[1].split('.')[0])
}
setTemp(Array)
setNewLabel(Array2)
})
} else {
axios.get(routesClient.outsideLoc + `3743011`).then((res) => {
const outWeather = res.data.contents.weather_out;
const Array = [];
const Array2 = [];
console.log(outWeather);
let i = outWeather.length - 9;
for (i; i < outWeather.length; i++) {
Array.push(outWeather[i].temp);
Array2.push(outWeather[i].collected_at.split("T")[1].split(".")[0]);
}
setTemp(Array);
setNewLabel(Array2);
});
}
}, []);
function ChartTemp({ temp, newLabel }) {
const options = {
legend: {
......
......@@ -6,42 +6,7 @@ import { callUserInfo } from '../utils/CheckDB';
import { routesClient } from './../routesClient';
import { isLogined } from './../utils/Auth';
function ChartWindSpeed() {
const [windSpd, setWindSpd] = useState([])
const [newLabel, setNewLabel] = useState([])
useEffect(() => {
if (isLogined()) {
axios.get(routesClient.userWeather, { withCredentials: true })
.then((res) => {
console.log('windsp', res.data.contents)
const userWeather = res.data.contents.weather_in
const Array = []
const Array2 = []
for (let i = 0; i < userWeather.length; i++) {
Array.push(userWeather[i].wind_speed)
Array2.push(userWeather[i].collected_at.split('T')[1].split('.')[0])
}
setWindSpd(Array)
setNewLabel(Array2)
})
}
else {
axios.get(routesClient.outsideLoc + `3743011`)
.then((res) => {
const outWeather = res.data.contents.weather_out
const Array = []
const Array2 = []
for (let i = 0; i < outWeather.length; i++) {
Array.push(outWeather[i].wind_speed)
Array2.push(outWeather[i].collected_at.split('T')[1].split('.')[0])
}
setWindSpd(Array)
setNewLabel(Array2)
})
}
}, [])
function ChartWindSpeed({windSpd, newLabel}) {
const options = {
legend: {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment