[ Launch: barchart ] 822b06813c642b9aaf00 by delenamalan
-
-
Save deanmalan/822b06813c642b9aaf00 to your computer and use it in GitHub Desktop.
favourite_series
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
{"description":"favourite_series","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"data.tsv":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"pingpong","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"ajax-caching":true} |
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
var data = [ | |
{series: "Orphan Black", rating: 8}, | |
{series: "OINTB", rating: 7}, | |
{series: "Justice", rating: 10}, | |
{series: "Modern Family", rating: 7} | |
]; | |
var margin = {top: 20, right: 20, bottom: 30, left: 40}, | |
width = 775 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var x = d3.scale.ordinal() | |
.rangeRoundBands([0, width], 0.1); | |
var y = d3.scale.linear() | |
.range([height, 0]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left"); | |
var color = d3.scale.category10(); | |
var svg = d3.select("svg") | |
.attr("width", width + margin.left + margin.right) | |
.attr("height", height + margin.top + margin.bottom) | |
.append("g") | |
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); | |
x.domain(data.map(function(d) { return d.series; })); | |
y.domain([0, d3.max(data, function(d, i) { return d.rating; })]); | |
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("Rating"); | |
svg.selectAll(".bar") | |
.data(data) | |
.enter().append("rect") | |
.attr("x", function(d) { return x(d.series); }) | |
.attr("width", x.rangeBand()) | |
.attr("y", function(d) { return y(d.rating); }) | |
.attr("height", function(d) { return height - y(d.rating); }) | |
.style("fill", function(d,i) { return color(i);}); | |
function type(d) { | |
d.frequency = +d.frequency; | |
return d; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment