Built with blockbuilder.org
Bitcoin data from Coindesk
Ether data from Etherscan
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
</head>
<body>
<script>
const svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500)
const margin = {top: 20, right: 20, bottom: 30, left: 50};
const width = +svg.attr("width") - margin.left - margin.right;
const height = +svg.attr("height") - margin.top - margin.bottom;
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
const parseBTCTime = d3.timeParse("%Y-%m-%d");
const parseETHTime = d3.timeParse("%m/%d/%Y");
const x = d3.scaleTime()
.rangeRound([0, width - 40]);
const y = d3.scaleLinear()
.rangeRound([height, 0]);
const BTCLine = d3.line()
.x(d => x(d.Date))
.y(d => y(d["Close Price"]));
const ETHLine = d3.line()
.x(d => x(d["Date(UTC)"]))
.y(d => y(d.Value));
d3.csv("coindesk-bpi-USD-close_data-2015-07-29_2017-09-23.csv", (d) => {
d.Date = parseBTCTime(d.Date);
d["Close Price"] = +d["Close Price"];
return d;
}, (error, data) => {
if (error) throw error;
x.domain(d3.extent(data, d => d.Date));
y.domain(d3.extent(data, d => d["Close Price"]));
g.append("g")
.attr("transform", `translate(0,${height})`)
.attr("fill", "dimgrey")
.call(d3.axisBottom(x))
.select(".domain")
.remove();
g.append("g")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "SteelBlue")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.text("BTC Price ($)");
g.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "SteelBlue")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 1.5)
.attr("d", BTCLine);
});
d3.csv("export-EtherPrice.csv", (d) => {
d["Date(UTC)"] = parseETHTime(d["Date(UTC)"]);
d.Value = +d.Value;
return d;
}, (error, data) => {
if (error) throw error;
x.domain(d3.extent(data, d => d["Date(UTC)"]));
y.domain(d3.extent(data, d => d.Value));
g.append("g")
.attr("transform", `translate(${width},0)`)
.attr("fill", "dimgrey")
.call(d3.axisLeft(y))
.append("text")
.attr("fill", "LightSalmon")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.text("ETH Price ($)");
g.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "LightSalmon")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("stroke-width", 1.5)
.attr("d", ETHLine);
});
</script>
</body>
https://d3js.org/d3.v4.min.js