xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
.line {
fill: none;
stroke: MidnightBlue;
stroke-width: 2px;
}
.line2 {
fill: none;
stroke: Orange;
stroke-width: 2px;
}
.grid line {
stroke: lightgrey;
stroke-opacity: 0.6;
shape-rendering: crispEdges
}
.grid path {
stroke-width: 0;
}
.area {
fill: none;
clip-path: url(#clip);
}
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; }
</style>
<link href='https://fonts.googleapis.com/css?family=Cabin:300,400' rel='stylesheet' type='text/css'>
<script src="https://d3js.org/d3.v4.min.js"></script>
</head>
<body>
<script>
// Feel free to change or delete any of the code you see in this editor!
var margin = {top: 20, right: 50, bottom: 30, left: 50},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom;
// parse the date / time
var parseTime = d3.timeParse("%Y");
var yearFormat = d3.timeFormat("%Y");
// set the ranges
var x = d3.scaleTime().range([0, width]);
var y0 = d3.scaleLinear().range([height, 0]);
var y1 = d3.scaleLinear().range([height, 0]);
// define the line
var valueline = d3.line()
.curve(d3.curveBasis)
.x(function(d) { return x(d.year); })
.y(function(d) { return y0(d.rvShipped); });
var valueline2 = d3.line()
.curve(d3.curveBasis)
.x(function(d) { return x(d.year); })
.y(function(d) { return y1(d.rvRetail); });
// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
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 + ")");
d3.csv("rvsales.csv", function(error, data) {
if (error) throw error;
// format the data
data.forEach(function(d) {
d.year = d.year;
d.rvShipped = +d.rv_shipped;
d.rvPct = +d.rv_pct;
d.rvRetail = +d.rv_retail;
d.retailPct = +d.retail_pct;
});
x.domain(d3.extent(data, function(d) { return d.year; }));
y0.domain([100, d3.max(data, function(d) { return d.rvShipped; })]);
y1.domain([4, d3.max(data, function(d) { return d.rvRetail; })]);
// Add the valueline path.
svg.append("path")
.data([data])
.attr("class", "line2")
.attr("d", valueline2);
var curtain = svg.append('rect')
.attr('x', 1)
.attr('height', height)
.attr('width', width -1)
.attr('class', 'curtain')
.style('fill', '#ffffff');
d3.selectAll(".curtain")
.transition()
.delay(4500)
.duration(4000)
.ease(d3.easeCubic)
.attr('width', 0)
.attr('transform', 'translate(' + width + ', 0)')
.remove();
svg.append("path")
.data([data])
.attr("class", "line")
.attr("d", valueline);
var curtain2 = svg.append('rect')
.attr('x', 1)
.attr('height', height)
.attr('width', width -1)
.attr('class', 'curtain2')
.style('fill', '#ffffff');
// Add the X Axis
svg.append("g")
.attr("transform", "translate(0," + height + ")")
.attr('x','margin.left')
.call(d3.axisBottom(x)
.tickFormat(d3.format("y")));
// Add the Y Axis
svg.append("g")
.call(d3.axisLeft(y0));
svg.append("g")
.attr("transform", "translate( " + width + ", 0 )")
.call(d3.axisRight(y1));
d3.selectAll(".curtain2")
.transition()
.delay(500)
.duration(4000)
.ease(d3.easeCubic)
.attr('width', 0)
.attr('transform', 'translate(' + width + ', 0)')
.remove()
});
</script>
</body>
https://d3js.org/d3.v4.min.js
https://d3js.org/d3.v4.min.js