Skip to content

Instantly share code, notes, and snippets.

@danharr
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danharr/9863526 to your computer and use it in GitHub Desktop.
Save danharr/9863526 to your computer and use it in GitHub Desktop.
Make an axis
name age
jack 2
tim 22
john 30
mary 58
pauline 24
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>show an axis from loaded CSV</title>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
.axis path,
.axis line {
fill: none;
stroke: black;
shape-rendering: crispEdges;
}
.axis text {
font-family: sans-serif;
font-size: 11px;
}
</style>
</head>
<body>
<script type="text/javascript">
var dataset; //Declare global var
d3.csv("data.csv", function(x) {
//Hand CSV data off to global variable so it's accessible later.
dataset = x;
//Call some other functions that
//generate your visualization, e.g.:
axis();
});
function axis() {
var x = d3.scale.linear()
.domain([0,60])
.range([0,400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient('bottom')
.tickPadding(8);
var svg = d3.select('body').append('svg')
.attr('class', 'chart')
.attr('width', 500)
.attr('height', 500);
svg.append('g')
.attr('class', 'x axis')
.attr('transform', 'translate(80,80)')
.call(xAxis);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment