Built with blockbuilder.org
xxxxxxxxxx
<html lang="ja">
<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.v4.js"></script>
<script>
var margin = {top: 20, right: 100, bottom: 30, left: 100},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
d3.csv("graduates.csv", function(error, data) {
if (error) throw error;
data.forEach(function(d) {
d.x = d.Year;
d.y = +d.Asians;
});
var xScale = d3.scaleLinear()
.domain([1993,2015])
.range([0, width]);
var yScale = d3.scaleLinear()
.domain([0, d3.max(data, function(d){ return d.y; })])
.range([height, 0]);
var xAxis = d3.axisBottom(xScale).tickFormat(function(d){ return d.x;})
var yAxis = d3.axisLeft(yScale);
var line = d3.line()
.x(function(d) { return xScale(d.x); })
.y(function(d) { return yScale(d.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(d3.axisBottom(xScale)
.ticks(10)
.tickFormat(d3.format("d")))
svg.append("g")
.attr("class", "y axis")
.call(yAxis)
svg.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 7)
.attr("dy", "0.71em")
.attr("text-anchor", "end")
.text("Asian Student");
svg.append("path")
.datum(data)
.attr("class", "line")
.attr("d", line(data));
});
</script>
</body>
</html>
Modified http://d3js.org/d3.v4.js to a secure url
https://d3js.org/d3.v4.js