Skip to content

Instantly share code, notes, and snippets.

@BetterProgramming
Created January 6, 2020 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BetterProgramming/f37d813453cc8a633d3f7c5f4d49e4a0 to your computer and use it in GitHub Desktop.
Save BetterProgramming/f37d813453cc8a633d3f7c5f4d49e4a0 to your computer and use it in GitHub Desktop.
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