Created
January 6, 2020 23:03
-
-
Save BetterProgramming/f37d813453cc8a633d3f7c5f4d49e4a0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import dayjs from "dayjs"; | |
export default function Graph({ priceArr, freqInDays, amountToInvest }) { | |
const numOfDays = priceArr.length; | |
let coinAmount = 0; | |
let totalInvested = 0; | |
let dataArr = []; | |
for (let i = 0; i < numOfDays; i += freqInDays) { | |
const coinPrice = priceArr[i][1]; | |
coinAmount += amountToInvest / coinPrice; | |
totalInvested += amountToInvest; | |
const total = coinAmount * coinPrice; | |
const date = dayjs(priceArr[i][0]).format("MM/DD/YYYY"); | |
dataArr.push({ | |
TotalInvested: totalInvested, | |
CoinAmount: coinAmount, | |
CoinPrice: coinPrice, | |
Total: total, | |
date: date, | |
}); | |
} | |
return <div style={styles.container}>Chart</div>; | |
} | |
const styles = { | |
container: { | |
maxWidth: 700, | |
margin: "0 auto", | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment