[ Launch: line chart ] 5094002 by trinary
-
-
Save trinary/5094002 to your computer and use it in GitHub Desktop.
line chart
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
{"description":"line chart","endpoint":"","display":"svg","public":true,"require":[{"name":"d3","url":"http://d3js.org/d3.v3.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":false,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01} |
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
data = [0, 11, 0, 0, 0, 0, 21, 9, 18, 9, 53, 46, 22, 34, 15, 15, 28, 16, 21, 10, 39, 52, 4, 14]; | |
tag = Object.keys(data) | |
console.log(data.length); | |
var margin = {top: 50, right: 30, bottom: 30, left: 90}, | |
width = 960 - margin.left - margin.right, | |
height = 500 - margin.top - margin.bottom; | |
var parseDate = d3.time.format("%d-%b-%y").parse; | |
var x = d3.scale.linear() | |
.range([0, width]); | |
var y = d3.scale.linear() | |
.range([height, 0]); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.tickSize(2) | |
.tickPadding(10) | |
.ticks(data.length-1) | |
.orient("bottom"); | |
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left"); | |
x.domain([0,data.length]); | |
y.domain([0,d3.max(data,function(d){return d;})]); | |
var line = d3.svg.line() | |
.x(function(d,i) {return x(i);}) | |
.y(function(d) {return y(d);}); | |
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 + ")"); | |
svg.append("g").transition() | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
svg.append("g") | |
.attr("class", "y axis") | |
.call(yAxis) | |
svg.append("path") | |
.datum(data) | |
.attr("transform","translate(-900,0)") | |
.attr("class", "line") | |
.style("fill","none") | |
.attr("d", line) | |
.transition() | |
.duration(2000) | |
.attr("transform","translate(0,0)") | |
.style("stroke","#2CA02C"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment