Skip to content

Instantly share code, notes, and snippets.

@davo

davo/index.html

Created Feb 13, 2015
Embed
What would you like to do?
Linea D, Junio y Julio 2014
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.x.axis path {
display: none;
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var margin = {top: 40, right: 20, bottom: 30, left: 50},
width = 1260 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var parseDate = d3.time.format("%m/%d/%Y").parse;
var x = d3.time.scale()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x).ticks(20)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.interpolate("monotone")
.x(function(d) { return x(d.fecha); })
.y(function(d) { return y(d.cantidad); });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.csv("linea_d_junio-julio.csv", function(error, data) {
data.forEach(function(d) {
d.fecha = parseDate(d.fecha);
d.cantidad = +d.cantidad;
console.log(d);
});
x.domain(d3.extent(data, function(d) { return d.fecha; }));
y.domain(d3.extent(data, function(d) { return d.cantidad; }));
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 6)
.attr("dy", ".71em")
.style("text-anchor", "end")
.text("Cantidad de pasajeros");
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line);
});
</script>
fecha cantidad
06/1/2014 4791
06/2/2014 7207
06/3/2014 7221
06/4/2014 7192
06/5/2014 7318
06/6/2014 7351
06/7/2014 5966
06/8/2014 4785
06/9/2014 7278
06/10/2014 7301
06/11/2014 7360
06/12/2014 4910
06/13/2014 7259
06/14/2014 5891
06/15/2014 4356
06/16/2014 7274
06/17/2014 7310
06/18/2014 7355
06/19/2014 7350
06/20/2014 4998
06/21/2014 5513
06/22/2014 4423
06/23/2014 7276
06/24/2014 7336
06/25/2014 7325
06/26/2014 7356
06/27/2014 7368
06/28/2014 6006
06/29/2014 4600
06/30/2014 7192
07/1/2014 7275
07/2/2014 7307
07/3/2014 7426
07/4/2014 7481
07/5/2014 5884
07/6/2014 4830
07/7/2014 7393
07/8/2014 7341
07/9/2014 4785
07/10/2014 7323
07/11/2014 7409
07/12/2014 6077
07/13/2014 4237
07/14/2014 7316
07/15/2014 7379
07/16/2014 7432
07/17/2014 7478
07/18/2014 7577
07/19/2014 6242
07/20/2014 5150
07/21/2014 7387
07/22/2014 7218
07/23/2014 7245
07/24/2014 7213
07/25/2014 7257
07/26/2014 5272
07/27/2014 4634
07/28/2014 7115
07/29/2014 7342
07/30/2014 7350
07/31/2014 7417
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment