JSFiddle - React, Tailwind, and code Playground
by Roydon DSouza
CSS
body { font: 12px Arial;}
.axis path,
.axis line {
fill: none;
stroke: grey;
stroke-width: 1;
shape-rendering: crispEdges;
}
path.historicRange.between {
fill:lightblue;
}
path.historicRange.above {
fill:darkred;
}
path.historicRange.below {
fill:seagreen;
}
path.dataline {
fill:none;
stroke-width:3;
}
JavaScript
// Set the dimensions of the canvas / graph
var margin = {top: 30, right: 20, bottom: 30, left: 50},
width = 600 - margin.left - margin.right,
height = 270 - margin.top - margin.bottom;
// Parse the date / time
var parseDate = d3.time.format("%d-%b-%y").parse;
// Set the ranges
var x = d3.scale.linear().range([0, width]);
var y = d3.scale.linear().range([height, 0]);
// Define the axes
var xAxis = d3.svg.axis().scale(x)
.orient("bottom").ticks(5);
var yAxis = d3.svg.axis().scale(y)
.orient("left").ticks(5);
// Define the value line path generator
var line = d3.svg.line()
.x( function(d) { return x(d.year); } )
.y( function(d) { return y(d.temp); } );
// Define the area path generator
var area = d3.svg.area()
.x( function(d) { return x(d.year); } )
.y0( function(d) { return y(d.min); } )
.y1( function(d) { return y(d.max); } );
// Adds the svg canvas
var svg = d3.select("body")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
var defs = svg.append("defs");
var plot = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
// Get the data
var data = [{
"year": 1,
"temp": 1960,
"min": 1920,
"max": 2070
}, {
"year": 2,
"temp": 1772,
"min": 1980,
"max": 2130
}, {
"year": 3,
"temp": 1810,
"min": 2010,
"max": 2160
}, {
"year": 4,
"temp": 1904,
"min": 2010,
"max": 2160
}, {
"year": 5,
"temp": 2204,
"min": 2015,
"max": 2165
}, {
"year": 6,
"temp": 1849,
"min": 2020,
"max": 2170
}, {
"year": 7,
"temp": 1868,
"min": 2025,
"max": 2175
}, {
"year": 8,
"temp": 1889,
"min":...