Built with blockbuilder.org
Last active
June 15, 2017 05:40
-
-
Save areologist/65ccabe6a5d4f9db0a4bb0d54f6aeb36 to your computer and use it in GitHub Desktop.
area chart
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
license: mit |
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
date | close | forecast | |
---|---|---|---|
1-Apr-13 | 48195.44 | 47795.442 | |
2-Apr-13 | 55461.72 | 55061.722 | |
3-Apr-13 | 55258.53 | 54858.532 | |
4-Apr-13 | 50127.83 | 49727.832 | |
5-Apr-13 | 76620.81 | 76220.812 | |
6-Apr-13 | 76620.81 | 76220.812 | |
7-Apr-13 | 76620.81 | 76220.812 | |
8-Apr-13 | 100571.68 | 100171.682 | |
9-Apr-13 | 91719.52 | 91319.522 | |
10-Apr-13 | 96239.32 | 95839.322 | |
11-Apr-13 | 98483.3 | 98083.32 | |
12-Apr-13 | 108620.08 | 118620.08200 | |
13-Apr-13 | 108620.08 | 118620.08200 | |
14-Apr-13 | 108620.08 | 118620.08200 | |
15-Apr-13 | 108170.13 | 118170.13200 | |
16-Apr-13 | 119098.3 | 129098.3200 | |
17-Apr-13 | 101325.71 | 111325.71200 | |
18-Apr-13 | 104259.05 | 114259.05200 | |
19-Apr-13 | 104641.65 | 114641.65200 | |
20-Apr-13 | 104641.65 | 114641.65200 | |
21-Apr-13 | 104641.65 | 114641.65 | |
22-Apr-13 | 111920.53 | 121920.532400 | |
23-Apr-13 | 104867.04 | 114867.042400 | |
24-Apr-13 | 109231.15 | 119231.152400 | |
25-Apr-13 | 57587.93 | 58587.932400 | |
26-Apr-13 | 62478.4 | 64478.42400 | |
27-Apr-13 | 62478.4 | 64478.42400 | |
28-Apr-13 | 62478.4 | 63478.42400 | |
29-Apr-13 | 81384.09 | 81384.092400 | |
30-Apr-13 | 77865.45 | 78865.452400 | |
1-May-13 | 82434.19 | 81434.192400 | |
2-May-13 | 79306.91 | 78306.912400 | |
3-May-13 | 38966.54 | 39966.542400 | |
4-May-13 | 38966.54 | 39966.542400 | |
5-May-13 | 38966.54 | 38966.542400 | |
6-May-13 | 47844.23 | 48844.232400 | |
7-May-13 | 66611.47 | 66611.472400 | |
8-May-13 | 71452.16 | 71452.162400 | |
9-May-13 | 37831.17 | 37831.172400 | |
10-May-13 | 48420.59 | 48420.592400 | |
11-May-13 | 48420.59 | 48420.592400 | |
12-May-13 | 48420.59 | 48420.592400 | |
13-May-13 | 56739.52 | 56739.522400 |
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
<!DOCTYPE html> | |
<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> | |
<div id ="chartID"></div> | |
<script> | |
var margin = {top:10, right:10, bottom:90, left:10}; | |
var width = 960 - margin.left - margin.right; | |
var height = 360 - margin.top - margin.bottom; | |
var xScale, yScale; | |
var svg = d3.select("#chartID").append("svg") | |
.attr("width", width+margin.left + margin.right) | |
.attr("height",height+margin.top + margin.bottom) | |
var margin = {top: 20, right: 20, bottom: 30, left: 50}, | |
width = +svg.attr("width") - margin.left - margin.right, | |
height = +svg.attr("height") - margin.top - margin.bottom, | |
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
var parseTime = d3.timeParse("%d-%b-%y"); | |
xScale = d3.scaleTime() | |
.rangeRound([0, width]); | |
yScale = d3.scaleLinear() | |
.rangeRound([height, 0]); | |
var area = d3.area() | |
.x(function(d) { return xScale(d.date); }) | |
.y1(function(d) { return yScale(d.close); }); | |
var area2 = d3.area() | |
.x(function(d) { return xScale(d.date); }) | |
.y1(function(d) { return yScale(d.forecast); }); | |
d3.tsv("data.tsv", function(d) { | |
d.date = parseTime(d.date); | |
d.close = +d.close; | |
return d; | |
}, function(error, data) { | |
if (error) throw error; | |
xScale.domain(d3.extent(data, function(d) { return d.date; })); | |
yScale.domain([0, d3.max(data, function(d) { return d.close; })]); | |
area.y0(yScale(0)); | |
area2.y0(yScale(0)); | |
g.append("path") | |
.datum(data) | |
.attr("fill", "#d189bf") | |
.attr("d", area2); | |
g.append("path") | |
.datum(data) | |
.attr("fill", "#6eb647") | |
.attr("d", area); | |
g.append("g") | |
.attr("transform", "translate(0," + height + ")") | |
.call(d3.axisBottom(xScale)); | |
g.append("g") | |
.call(d3.axisLeft(yScale)) | |
.append("text") | |
.attr("fill", "#000") | |
.attr("transform", "rotate(-90)") | |
.attr("y", 6) | |
.attr("dy", "0.71em") | |
.attr("text-anchor", "end") | |
.text("Price ($)"); | |
}); | |
document.addEventListener("DOMContentLoaded", resize); | |
d3.select(window).on('resize', resize); | |
function resize() { | |
width = parseInt(d3.select('#chartID').style('width'), 10); | |
width = width - margin.left - margin.right; | |
height = parseInt(d3.select("#chartID").style("height")); | |
height = height - margin.top - margin.bottom; | |
console.log('width, height: ', [width, height]); | |
xScale = d3.scaleTime() | |
.rangeRound([0, width]); | |
yScale = d3.scaleLinear() | |
.rangeRound([height, 0]); | |
svg | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom); | |
//xScale.domain(d3.extent(data, function(d) { return d.date; })); | |
//yScale.domain([0, d3.max(data, function(d) { return d.close; })]); | |
area.y0(yScale(0)); | |
} | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment