JSFiddle - React, Tailwind, and code Playground
CSS
.axis text {
font: bold 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
stroke: #6aa0cc;
shape-rendering: crispEdges;
}
body {
font: 10px sans-serif;
shape-rendering: crispEdges;
}
.grid-background,
.grid-background-light {
fill: #9cc3e4;
fill-opacity: 1;
}
.grid-background-light {
fill-opacity: .3;
}
.grid line,
.axis line {
stroke: #fff;
stroke-width: 2;
}
.grid .minor line {
stroke: #fff;
stroke-opacity: .5;
}
/* Vertical lines for weeks in the year */
.minorTicks line {
stroke: #fff;
stroke-width: 1;
stroke-opacity: .4;
}
.grid text,
.minorTicks text {
display: none;
}
.grid path,
.axis path,
.minorTicks path {
display: none;
}
.today,
.today line,
.today path {
fill: #ffb958;
stroke: #ffb958;
stroke-width: 1;
}
JavaScript
var margin = {top: 10, right: 10, bottom: 30, left: 10},
width = 1200 - margin.left - margin.right,
height = 800 - margin.top - margin.bottom;
var x = d3.time.scale()
.domain([new Date(2015, 0, 1), new Date(2015, 11, 31)])
.range([0, width]);
var y = d3.scale.linear()
.domain([0,1000])
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.months)
.tickSize(30, 0)
.tickFormat(d3.time.format("%B"));
var xAxisMinor = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.months)
.tickSize(-height)
.tickFormat(d3.time.format("%B"));
var xAxisMinorTicks = d3.svg.axis()
.scale(x)
.orient("bottom")
.ticks(d3.time.weeks)
.tickSize(-height)
.tickFormat(d3.time.format("%U"));
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 + ")");
svg.append("rect")
.attr("class", "grid-background-light")
.attr("width", width)
.attr("height", height + margin.bottom)
.attr("rx", 5)
.attr("ry", 5);
svg.append("rect")
.attr("class", "grid-background")
.attr("width", width)
.attr("height", 30)
.attr("transform", "translate(0," + (height) + ")");
svg.append("g")
.attr("class", "minorTicks")
.attr("transform", "translate(0," + height + ")")
.call(xAxisMinorTicks)
.selectAll(".tick")
.data(x.ticks(52), function(d) { return d; })
.exit()
.classed("minorTicks", true);
svg.append("g")
.attr("class", "grid")
.attr("transform", "translate(0," + height + ")")
.call(xAxisMinor)
.selectAll(".tick")
.data(x.ticks(12), function(d) { return d; })
.exit()
.classed("minor", true);
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.selectAll(".tick text")
...