Skip to content

Instantly share code, notes, and snippets.

@chiffenok
Last active October 24, 2017 10:31
Show Gist options
  • Save chiffenok/8b840413555ab8a128d57f311a76e602 to your computer and use it in GitHub Desktop.
Save chiffenok/8b840413555ab8a128d57f311a76e602 to your computer and use it in GitHub Desktop.
tourist visit Brazil
license: mit
<!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>
<svg></svg>
<div></div>
<body>
<script>
var width = 800;
var height = 300;
var margin = {top: 20, bottom: 20, left: 20, right: 20};
d3.csv('td.europe_by_coninent_year.csv', (err, data) => {
data.forEach( d => {
d.Year = d3.timeParse("%Y")(d.Year);
d.Year = new Date(d.date);
d.visits = d.visits;
})
// scales
var xExtent = d3.extent(data, d => d.Year);
var xScale = d3.scaleTime()
.domain(xExtent)
.range([margin.left, width - margin.right]);
console.log(data.visits);
var yScale = d3.scaleLinear()
.domain([0, d3.max(data, function(d) { return d.visits; })])
.range([height - margin.bottom, margin.top]);
//create the rectangles
var svg = d3.select('svg');
var rect = svg.selectAll('rect')
.data(data)
.enter().append('rect')
.attr('width', 5)
.attr('height', function(d) {return height - yScale(d.visits)})
.attr('x', function(d) {return xScale(d.Year)})
.attr('y', function(d) {return yScale(d.visits)});
d3.select('div')
.text(d3.max(data.visits));
});
function type(d) {
d.visits = +d.visits; // coerce to number
return d;
}
</script>
</body>
id Continent Year visits
1 Europe 1989 344055
2 Europe 1990 326477
3 Europe 1991 303948
4 Europe 1992 337728
5 Europe 1993 290181
6 Europe 1994 407973
7 Europe 1995 509153
8 Europe 1996 671152
9 Europe 1997 701684
10 Europe 1998 1144545
11 Europe 1999 1227837
12 Europe 2000 1305674
13 Europe 2001 1430724
14 Europe 2002 1394178
15 Europe 2003 1522694
16 Europe 2004 1834164
17 Europe 2005 2069221
18 Europe 2006 1951528
19 Europe 2007 1902081
20 Europe 2008 1776333
21 Europe 2009 1612665
22 Europe 2010 1614864
23 Europe 2011 1621183
24 Europe 2012 1652205
25 Europe 2013 1636569
26 Europe 2014 1847834
27 Europe 2015 1631514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment