diff --git a/app/GraphPage.jsx b/app/GraphPage.jsx index 17b27c2..b404da2 100644 --- a/app/GraphPage.jsx +++ b/app/GraphPage.jsx @@ -3,6 +3,7 @@ import styled from '@emotion/styled' import { Card, Grid, TextField, Typography, Box, Container } from '@mui/material'; import { DatePicker } from '@mui/x-date-pickers'; import { LineChart, Line, XAxis, YAxis } from 'recharts'; +import { useState } from 'react'; const bitcoinCSV = `Date,Price 09/01/2023,26209.50 @@ -135,6 +136,13 @@ const CSVtoJSON = (csv) => { return monthlyPrices.reverse(); } +const selectPriceDates = (startDateStr, json) => { + let startDateObj = new Date(startDateStr); + let returnJson = json.filter(obj => new Date(obj.date) >= startDateObj); + console.log(returnJson); + return returnJson; +} + const BTCWorkers = ( @@ -179,9 +187,13 @@ const CustomDiv = styled.div` width: 100% `; -const data = CSVtoJSON(bitcoinCSV); + const GraphPage = () => { + const [selectedDate, setSelectedDate] = useState(); + + const json = CSVtoJSON(bitcoinCSV); + const data = selectPriceDates(selectedDate, json); return ( @@ -195,7 +207,7 @@ const GraphPage = () => { investment date - + {setSelectedDate(date)}}/> amount