Built with blockbuilder.org
xxxxxxxxxx
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Line Chart</title>
<style>
.axis path,
.axis line{
fill: none;
stroke: black;
}
.tick text{
font-size: 12px;
}
.line{
fill: none;
stroke: blue;
stroke-width: 2px;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v3.js"></script>
<script>
var margin = {top: 20, right: 100, bottom: 30, left: 100},
width = 1000 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
var majors = ["Biological Sciences", "Chemistry", "Computer Science and Math"]
var i = 0, j = width/4;
d3.csv("graduates.csv", function(error, data) {
if (error) throw error;
majors.forEach(function(major) {
if(data.Major == major) {
data.x = data.Year;
data.y = +data.Masters;
var xScale = d3.scale.linear()
.domain([1993,2015])
.range([i, j]);
i = j;
j = j*2;
var yScale = d3.scale.linear()
.domain([0, d3.max(data, function(d){ console.log(d.Masters); return d.y; })])
.range([height, 0]);
var xAxis = d3.svg.axis().scale(xScale).orient("bottom").tickFormat(d3.format("d"));
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left");
var line = d3.svg.line()
.x(xScale(data.x))
.y(yScale(data.y));
var svg = d3.select("body").append("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")
.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("class", "line")
.attr("d", line(data));
}
});
});
</script>
</body>
</html>
Modified http://d3js.org/d3.v3.js to a secure url
https://d3js.org/d3.v3.js