This bar graph shows global mean temperature anomaly since 2001. temperature anomaly is deviation from a base average temperature. the base average temperature for this study is 1951-1980 average global temperatures. The data is obtained from National Aeronautics and Space Administration, Goddard Institute for Space Studies data base .
Built with blockbuilder.org
forked from curran'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: 15pt;
font-family: 'sans-serif';
alignment-baseline: middle;
fill: #000f42;
}
.number, .subtitle {
font-size: 14pt;
font-family: 'sans-serif';
alignment-baseline: middle;
fill: #00114c;
}
.bar {
fill: #ff9b05;
}
</style>
</head>
<body>
<script>
const width = 960;
const height = 900;
const margin = {
left: 60,
right: 200,
top: 90,
bottom: 52
}
const svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
svg.append('text')
.attr('class', 'label')
.attr('x', 200)
.attr('y', 75)
.text('Global Mean Temperature Anomalies Since 2001 in C');
const g = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`)
const data = [
{
name: "2001",
value: 0.53
},
{
name: "2002",
value: 0.62
},
{
name: "2003",
value: 0.61
},
{
name: "2004",
value: 0.63
},
{
name: "2005",
value: 0.67
},
{
name: "2006",
value: 0.62
},
{
name: "2007",
value: 0.64
},
{
name: "2008",
value: 0.52
},
{
name: "2009",
value: 0.64
},
{
name: "2010",
value: 0.70
},
{
name: "2011",
value: 0.58
},
{
name: "2012",
value: 0.62
},
{
name: "2013",
value: 0.64
},
{
name: "2014",
value: 0.73
},
{
name: "2015",
value: 0.87
},
{
name: "2016",
value: 1
},
];
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))
.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')
.attr('class', 'bar')
.attr('width', d => xScale(xValue(d)))
.attr('height', yScale.bandwidth())
.attr('fill', 'black');
groupsEnter
.append('text')
.attr('class', 'label')
.attr('x', 15)
.attr('y', yScale.bandwidth() / 2)
.text(yValue);
groupsEnter
.append('text')
.attr('class', 'number')
.attr('x', d => xScale(xValue(d)) + 20)
.attr('y', yScale.bandwidth() / 2)
.text(d => `${xValue(d)}
(°C)`);
</script>
</body>
https://d3js.org/d3.v4.min.js