JSFiddle - React, Tailwind, and code Playground
by emturano
HTML
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<svg id="myChart" class="svg"></svg>
CSS
.svg text {
fill: black;
font: 10px sans-serif;
font-weight: bold;
text-anchor: start;
}
.axis {
font: 10px sans-serif;
}
.axis path {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.tick line {
stroke: gray;
opacity: 0.6;
}
JavaScript
var margin = {top: 40, right: 45, bottom: 30, left: 40};
var width = 400;
var height = 200;
svg = d3.select("#myChart")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var xScale = d3.scale.linear()
.range([0, width]);
var xAxis = d3.svg.axis()
.scale(xScale)
.tickSize(-height,0,0)
.orient("bottom");
var yScale = d3.scale.linear()
.range([height, 0]);
var yAxis = d3.svg.axis()
.scale(yScale)
.orient("left");
svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
svg.append("text")
.attr("class", "title")
.attr("x", width/2)
.attr("y", 0 - (margin.top / 2))
.attr("text-anchor", "middle")
.text("Testing");