This bar chart was created to list the acceptance rates of colleges that my son is looking into. It creates a visual for him to see the difference between each school when making a decision to apply. This list will grow as he chooses more schools.
Source: Wikipedia - Catholic University, Wikipedia - Baylor, Wikipedia - UNC Chapel Hill, Wikipedia - Emery, Wikipedia - Georgia Tech, Wikipedia - Rice, Wikipedia - Carnegie Mellon, Wikipedia - Vanderbilt, Wikipedia - UChicago,
Built with blockbuilder.org
forked from curran's block: Extremist Murders in the US
forked from anonymous's block: Extremist Murders in the US
xxxxxxxxxx
<head>
<meta charset="utf-8">
<script src="https://d3js.org/d3.v4.min.js"></script>
<style>
body {
margin:0px;
}
.label {
font-size: 12pt;
font-family: 'sans-serif';
alignment-baseline: middle;
fill: white;
}
.number, {
font-size: 12pt;
font-family: 'sans-serif';
alignment-baseline: middle;
fill: #000000;
}
.subtitle {
font-size: 18pt;
font-family: 'sans-serif';
alignment-baseline: middle;
fill: #000000;
}
.bar {
fill: #228B22;
}
</style>
</head>
<body>
<script>
const width = 960;
const height = 500;
const margin = {
left: 50,
right: 90,
top: 80,
bottom: 50
}
const svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height)
;
svg.append('text')
.attr('class', 'subtitle')
.attr('x', margin.left)
.attr('y', 86)
.text('Acceptance rates to college we are looking at');
const g = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`)
const data = [
{
name: "Catholic University",
value: 76
},{
name: "Baylor",
value: 44
},
{
name: "UNC Chapel Hill",
value: 26
},
{
name: "Emery",
value: 25.2
},
{
name: "Georgia Tech",
value: 25
},
{
name: "Rice University",
value: 15.3
},
{
name: "Carnegie Mellon",
value: 13.7
},
{
name: "Vanderbilt",
value: 10.7
},
{
name: "UChicago",
value: 7.9
}
];
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const xValue = d => d.value;
const yValue = d => d.name;
const xScale = d3.scaleLinear()
.domain([0, d3.max(data, xValue)])
.range([0, innerWidth]);
const yScale = d3.scaleBand()
.domain(data.map(yValue).reverse())
.range([innerHeight, 0])
.padding(0.272);
const groups = g.selectAll('g').data(data);
const groupsEnter = groups
.enter().append('g')
.attr('transform', d => `translate(0, ${yScale(yValue(d))})`);
groupsEnter
.append('rect')
.transition()
.delay(20)
.duration(2000)
.attr('duration', 2000)
.attr('class', 'bar')
.attr('width', d => xScale(xValue(d)))
.attr('height', yScale.bandwidth())
.attr('fill', 'black');
groupsEnter
.append('text')
.attr('opacity', 0)
.transition()
.delay(2000)
.attr('duration', 2000)
.attr('opacity', 1)
.attr('class', 'label')
.attr('x', 15)
.attr('y', yScale.bandwidth() / 2)
.text(yValue);
const percentFormat = d3.format(",.1%");
const xPercent = d => percentFormat(xValue(d) / xScale.domain()[1]);
groupsEnter
.append('text')
.attr('class', 'number')
.attr('x', d => xScale(xValue(d)) + 8)
.attr('y', yScale.bandwidth() / 2)
.text(d => `${xValue(d)}%`);
//.text(d => `${xValue(d)} (${xPercent(d)})`);
</script>
</body>
https://d3js.org/d3.v4.min.js