View this code at http://livecoding.io/9709744
Created
March 22, 2014 16:21
-
-
Save ramnathv/9709744 to your computer and use it in GitHub Desktop.
created by http://livecoding.io
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
{ | |
"libraries": [ | |
"d3" | |
], | |
"mode": "css", | |
"layout": "fullscreen mode (vertical)", | |
"resolution": "reset" | |
} |
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
/* css goes here */ | |
.axis path, | |
.axis line { | |
fill: none; | |
stroke: none; | |
shape-rendering: crispEdges; | |
} | |
.axis text { | |
font-family: sans-serif; | |
font-size: 13px; | |
fill: gray; | |
} |
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
<!-- html goes here --> | |
<div id='vis'></div> |
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
/* javascript goes here */ | |
var dataset = [5, 10, 13, 19, 21, 25, 22, 18, 15, 13, | |
11, 12, 15, 20, 18, 17, 16, 18, 23, 40 | |
]; | |
var w = 700, | |
h = 350 | |
// boilerplate setup code | |
var margin = {top: 20, right: 10, bottom: 20, left: 10}, | |
width = w - margin.left - margin.right, | |
height = h - margin.top - margin.bottom, | |
barWidth = dataset/length | |
var svg = d3.select("#vis") | |
.append("svg") | |
.attr("width", w) | |
.attr("height", h) | |
.append("g") | |
.attr("transform", | |
["translate(", margin.left, ",", margin.top, ")"].join("") | |
) | |
var yScale = d3.scale.linear() | |
.range([height, 0]) | |
.domain([0, d3.max(dataset)]) | |
var xScale = d3.scale.ordinal() | |
.domain(d3.range(dataset.length)) | |
.rangeRoundBands([0, width], 0.05) | |
var colorScale = d3.scale.quantize() | |
.domain([0, d3.max(dataset)]) | |
.range(["steelblue", "darkorange", "red", "yellow"]) | |
var bars = svg.selectAll('rect') | |
.data(dataset) | |
.enter() | |
.append("rect") | |
.attr("class", "bar") | |
bars | |
.attr("x", function(d, i){return xScale(i)}) | |
.attr("y", function(d){return yScale(d)}) | |
.attr("height", function(d, i){ | |
return height - yScale(d) | |
}) | |
.attr("width", xScale.rangeBand()) | |
.attr("fill", colorScale) | |
// initialize xAxis | |
var xAxis = d3.svg.axis() | |
.scale(xScale) | |
.orient("bottom") | |
.ticks(5) | |
// invoke xAxis in context of visualization | |
svg | |
.append("g") | |
.attr("class", "axis") | |
.attr("transform", "translate(0," + (height) + ")") | |
.call(xAxis) |
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
{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment