Skip to content

Instantly share code, notes, and snippets.

@emilyw15
Last active October 16, 2017 22:12
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 emilyw15/b8fe8d2b0c9ae26f8d7fd4758a780737 to your computer and use it in GitHub Desktop.
Save emilyw15/b8fe8d2b0c9ae26f8d7fd4758a780737 to your computer and use it in GitHub Desktop.
CFPB Student Loan Complaints
license: mit
createddate product CountOfProduct
1/1/2017 Student loan 1
1/3/2017 Student loan 4
1/4/2017 Student loan 4
1/5/2017 Student loan 6
1/6/2017 Student loan 2
1/7/2017 Student loan 2
1/8/2017 Student loan 1
1/9/2017 Student loan 2
1/10/2017 Student loan 8
1/11/2017 Student loan 6
1/12/2017 Student loan 1
1/13/2017 Student loan 2
1/14/2017 Student loan 2
1/15/2017 Student loan 2
1/17/2017 Student loan 6
1/18/2017 Student loan 4
1/19/2017 Student loan 30
1/20/2017 Student loan 23
1/21/2017 Student loan 6
1/22/2017 Student loan 8
1/23/2017 Student loan 5
1/24/2017 Student loan 10
1/25/2017 Student loan 9
1/26/2017 Student loan 12
1/27/2017 Student loan 6
1/28/2017 Student loan 1
1/30/2017 Student loan 2
1/31/2017 Student loan 9
2/1/2017 Student loan 2
2/2/2017 Student loan 4
2/3/2017 Student loan 7
2/4/2017 Student loan 3
2/5/2017 Student loan 2
2/6/2017 Student loan 7
2/7/2017 Student loan 7
2/8/2017 Student loan 6
2/9/2017 Student loan 8
2/10/2017 Student loan 5
2/12/2017 Student loan 3
2/13/2017 Student loan 7
2/14/2017 Student loan 8
2/15/2017 Student loan 7
2/16/2017 Student loan 5
2/17/2017 Student loan 4
2/18/2017 Student loan 2
2/19/2017 Student loan 1
2/20/2017 Student loan 1
2/21/2017 Student loan 5
2/22/2017 Student loan 4
2/23/2017 Student loan 1
2/24/2017 Student loan 4
2/27/2017 Student loan 5
2/28/2017 Student loan 9
3/1/2017 Student loan 5
3/2/2017 Student loan 5
3/3/2017 Student loan 2
3/4/2017 Student loan 1
3/5/2017 Student loan 1
3/6/2017 Student loan 1
3/7/2017 Student loan 3
3/8/2017 Student loan 1
3/9/2017 Student loan 3
3/10/2017 Student loan 3
3/12/2017 Student loan 1
3/13/2017 Student loan 2
3/14/2017 Student loan 12
3/15/2017 Student loan 3
3/16/2017 Student loan 6
3/17/2017 Student loan 6
3/18/2017 Student loan 3
3/20/2017 Student loan 1
3/21/2017 Student loan 3
3/22/2017 Student loan 9
3/23/2017 Student loan 2
3/24/2017 Student loan 2
3/25/2017 Student loan 1
3/26/2017 Student loan 1
3/27/2017 Student loan 4
3/28/2017 Student loan 6
3/29/2017 Student loan 1
3/30/2017 Student loan 4
3/31/2017 Student loan 3
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://d3js.org/d3.v4.min.js"></script>
<title>CFPB Student Loan Complaints</title>
<style>
body {
margin: 0px;
}
.domain {
display: none;
}
.tick line {
stroke: #C0C0BB;
}
.tick text {
fill: #8E8883;
font-size: 10pt;
font-family: sans-serif;
}
.axis-label {
fill: #635F5D;
font-size: 20pt;
font-family: sans-serif;
}
#chart {
position: fixed;
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
}
</style>
</head>
<body>
<div id="chart"></div>
<svg width="960" height="500"></svg>
<script>
const xValue = d => d.createddate;
const xLabel = 'Date';
const yValue = d => d.CountOfProduct;
const yLabel = 'Number of Complaints';
const margin = { left: 120, right: 30, top: 20, bottom: 120 };
var chartDiv = document.getElementById("chart")
var svg = d3.select(chartDiv).append("svg")
//const svg = d3.select('svg');
//const width = svg.attr('width');
//const height = svg.attr('height');
//const innerWidth = width - margin.left - margin.right;
//const innerHeight = height - margin.top - margin.bottom;
function redraw(){
var width = chartDiv.clientWidth;
var height = chartDiv.clientHeight;
svg
.attr("width", width)
.attr("height", height);
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const g = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`);
const xAxisG = g.append('g')
.attr('transform', `translate(0, ${innerHeight})`);
const yAxisG = g.append('g');
xAxisG.append('text')
.attr('class', 'axis-label')
.attr('x', innerWidth / 2)
.attr('y', 100)
.text(xLabel);
yAxisG.append('text')
.attr('class', 'axis-label')
.attr('x', -innerHeight / 2)
.attr('y', -60)
.attr('transform', `rotate(-90)`)
.style('text-anchor', 'middle')
.text(yLabel);
var parseTime = d3.timeParse("%-m/%-d/%Y");
const xScale = d3.scaleTime();
const yScale = d3.scaleLinear();
const xAxis = d3.axisBottom()
.scale(xScale)
.tickPadding(15)
.tickSize(-innerHeight);
const yTicks = 5;
const yAxis = d3.axisLeft()
.scale(yScale)
.ticks(yTicks)
.tickPadding(15)
.tickSize(-innerWidth);
const line = d3.line()
.x(d => xScale(xValue(d)))
.y(d => yScale(yValue(d)))
.curve(d3.curveBasis);
const row = d => {
d.createddate = new Date(d.createddate);
d.CountOfProduct = +d.CountOfProduct;
return d;
};
d3.csv('cfpb_student_loan.csv', row, data => {
xScale
.domain(d3.extent(data, xValue))
.range([0, innerWidth]);
yScale
.domain(d3.extent(data, yValue))
.range([innerHeight, 0])
.nice(yTicks);
//var lines = svg.selectAll("line").data(data)
//lines
//.enter().append("path")
//.style("fill","none")
//.style("stroke", "steelblue")
//.style("stroke-width",4)
//.merge(lines)
//.attr("d", line(data));
g.append('path')
.attr('fill', 'none')
.attr('stroke', 'steelblue')
.attr('stroke-width', 4)
.attr('d', line(data));
xAxisG.call(xAxis);
yAxisG.call(yAxis);
});
}
redraw();
//window.addEventListener("resize",redraw);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment