[ Launch: line_chart1 ] 5361671 by sdawson
-
-
Save sdawson/5361671 to your computer and use it in GitHub Desktop.
line_chart1
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":"line_chart1","endpoint":"","display":"svg","public":true,"require":[],"fileconfigs":{"inlet.js":{"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},"test_data.csv":{"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 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 svg = d3.select("svg"); | |
var data = tributary.test_data; | |
data.forEach(function(d) { | |
d.x = +d.x; | |
d.y = +d.y; | |
}); | |
var margin = {top: 20, right: 20, bottom: 30, left: 50}, | |
width = 405 - margin-left - margin.right, | |
height = 367 - margin.top - margin.bottom; | |
var g = svg.append("g") | |
.attr("transform", "translate" + margin.left + "," + margin.top + ")"); | |
var lines = lineChart() | |
.data(data) | |
.width(328) | |
.height(322); | |
lines(g); | |
function lineChart() { | |
var data = []; | |
var width = 300; | |
var height = 300; | |
var chart = function(g) { | |
var x = d3.scale.linear() | |
.range([0, width]); | |
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 line = d3.svg.line() | |
.x(function(d) { return x(d.x); }) | |
.y(function(d) { return y(d.y); }); | |
x.domain(d3.extent(data, function(d) { return d.x; })); | |
y.domain(d3.extent(data, function(d) { return d.y; })); | |
g.append("g") | |
.attr("class", "x axis") | |
.attr("transform", "translate(0," + height + ")") | |
.call(xAxis); | |
g.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("Price (@$)"); | |
g.append("path") | |
.datum(data) | |
.attr("class", "line") | |
.attr("d", line); | |
} | |
return chart; | |
} | |
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
x | y | |
---|---|---|
1 | 5 | |
2 | 60 | |
3 | 42 | |
4 | 109 | |
5 | 27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment