Skip to content

Instantly share code, notes, and snippets.

@AMcNeice
Created January 13, 2012 18:41
Show Gist options
  • Save AMcNeice/1607987 to your computer and use it in GitHub Desktop.
Save AMcNeice/1607987 to your computer and use it in GitHub Desktop.
Simple Line in d3
<html>
<head>
<title> Simple Line in d3 </title>
<script src = "https://raw.github.com/mbostock/d3/master/d3.js">
</script>
<style>
path {
stroke: #666;
stroke-width: 5px;
fill: none;
}
</style>
</head>
<body>
<div id = "graph"
style = "float: left;
width: 300px;
height: 100px;">
</div>
<script>
var graph = d3.select("#graph")
.append("svg:svg")
.attr("width", "100%")
.attr("height", "100%");
var data = [3, 6, 2, 7, 5, 2, 1, 3, 8, 9];
var x = d3.scale.linear()
.domain([0,100])
.range([0, 100]);
var y = d3.scale.linear()
.domain([0, 100])
.range([0, 100]);
var line = d3.svg.line()
.x(function(d,i){
console.log('Plotting the value for x: ' + d + ' index ' + i + ' value ' + x(i));
return x(i*30);
})
.y(function(d,i){
console.log('Plotting the value for y: ' + d + ' index ' + i + ' value ' + y(d));
return y(d*10)
})
graph.append("svg:path").attr("d",line(data));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment