Created
March 14, 2013 08:02
-
-
Save mauroSolis/5159659 to your computer and use it in GitHub Desktop.
Grafica sobre peliculas
This file contains hidden or 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> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script type="text/javascript" src="d3.js"></script> | |
<style> | |
.axis path{ | |
fill:none; | |
stroke: black; | |
} | |
.axis { | |
font-size:8pt; | |
font-family:sans-serif; | |
} | |
.tick { | |
fill:none; | |
stroke:black; | |
} | |
circle{ | |
stroke:black; | |
stroke-width:0.5px; | |
fill:RoyalBlue; | |
opacity:0.6; | |
} | |
</style> | |
<script> | |
function draw(data) { | |
"use strict"; | |
var colores = [ | |
{ | |
"colorRelleno":"#FF7F11", | |
"colorBorde":"#BB3300" | |
}, | |
{ | |
"colorRelleno":"#990066", | |
"colorBorde":"#552222" | |
}, | |
{ | |
"colorRelleno":"#78F9FF", | |
"colorBorde":"#4455BB" | |
}, | |
{ | |
"colorRelleno":"#FFCCCC", | |
"colorBorde":"#BB8888" | |
}, | |
{ | |
"colorRelleno":"#FF7777", | |
"colorBorde":"#BB3333" | |
}, | |
{ | |
"colorRelleno":"#6688FF", | |
"colorBorde":"#2244BB" | |
}, | |
{ | |
"colorRelleno":"#AADB00", | |
"colorBorde":"#997700" | |
}, | |
{ | |
"colorRelleno":"#8BB88F", | |
"colorBorde":"#444444" | |
}, | |
{ | |
"colorRelleno":"#3B88FF", | |
"colorBorde":"#7788BB" | |
}, | |
{ | |
"colorRelleno":"#4FBC88", | |
"colorBorde":"#BBAA44" | |
} | |
]; | |
var margin = 130, | |
width = 1000, | |
height = 800, | |
radio_min = 30, | |
radio_max = 70, | |
margen_izq = 65, | |
margen_der = 15, | |
margen_sup = 50, | |
margen_inf = 30+(30*5)+30+10, | |
x_extent = d3.extent(data, function(d){return d.year}), | |
y_extent = d3.extent(data, function(d){return d.production_budget}); | |
var x_scale = d3.scale.linear() | |
.range([margin,width-margin]) | |
.domain(x_extent) | |
var y_scale = d3.scale.linear() | |
.range([height-margin, margin]) | |
.domain(y_extent) | |
var radio_extent = d3.extent(data, function(d){return d.worldwide_grosses}); | |
var radio_scale = d3.scale.linear() | |
.domain(radio_extent) | |
.range([radio_min, radio_max]); | |
var x_axis = d3.svg.axis().scale(x_scale) | |
var y_axis = d3.svg.axis().scale(y_scale).orient('left') | |
d3.select("body") | |
.append('svg') | |
.attr('width', width) | |
.attr('height', height) | |
.selectAll('circle') | |
.data(data) | |
.enter() | |
.append('circle') | |
.attr('cx', function(d){return x_scale(d.year)}) | |
.attr('cy', function(d){return y_scale(d.production_budget)}) | |
.style("fill", function(d){return colores[d.id].colorRelleno}) | |
.attr("r", function(d){return radio_scale(d.worldwide_grosses)}); | |
d3.select("svg") | |
.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(30," + (height-margin) + ")") | |
.call(x_axis); | |
d3.select("svg") | |
.append("g") | |
.attr("class", "y axis") | |
.attr("transform", "translate(" + margin + ", 0 )") | |
.call(y_axis); | |
d3.select('.y.axis') | |
.append('text') | |
.text('production budget') | |
.attr('transform', "rotate (-90, -43, 50) translate(-380)") | |
d3.select('.x.axis') | |
.append('text') | |
.text('YEAR') | |
.attr('x', function(){return (width / 2) - margin}) | |
.attr('y', margin/2.5); | |
} | |
</script> | |
</head> | |
<body> | |
<script> | |
d3.json('datosPeliculas.json', draw); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment