JSFiddle - React, Tailwind, and code Playground

by Nilesh Ramteke

HTML

<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<script>

var margin = {top: 40, right: 20, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var formatPercent = d3.format(".0%");

var x = d3.scale.ordinal()
    .rangeRoundBands([0, width], .1);

var y = d3.scale.linear()
    .range([height, 0]);

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom");
    
var yAxis = d3.svg.axis()
    .scale(y)
    .orient("left")
    .tickFormat(formatPercent);

/* var tip = d3.tip()
  .attr('class', 'd3-tip')
  .offset([-10, 0])
  .html(function(d) {
    return "<span style='color:white'>" + d.date + "</span>";
  }) */

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.call(tip); */

var data = [{date : 'Jan 2000', price : 20.46},
            {date : 'Feb 2000', price : 50.42},
            {date : 'Mar 2000', price : 148.58},
            {date : 'Apr 2000', price : 152.43},
            {date : 'May 2000', price : 520.6},
            {date : 'Jun 2000', price : 854.6},
            {date : 'Jul 2000', price : 330.83},
            {date : 'Aug 2000', price : 517.68},
            {date : 'Sep 2000', price : 236.51},
            {date : 'Oct 2000', price : 429.4},
            {date : 'Nov 2000', price : 114.95},
            {date : 'Dec 2000', price : 420.28},
            {date : 'Jan 2001', price : 366.01},
            {date : 'Feb 2001', price : 539.94},
            {date : 'Mar 2001', price : 60.33},
           ];

x.domain(data.map(function(d) { return d.date; }));
y.domain([0, d3.max(data, function(d) { return d.price; })]);

svg.append("g")
    .attr("class", "x axis")
    .attr("transform", "translate(0," + height + ")")
    /* .append("text")  
   ...

CSS

body {
  font: 10px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.bar {
  fill: orange;
}

.x.axis path {
  display: none;
}

.d3-tip {
  line-height: 1;
  font-weight: bold;
  padding: 12px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border-radius: 2px;
}

/* Creates a small triangle extender for the tooltip */
.d3-tip:after {
  box-sizing: border-box;
  display: inline;
  font-size: 10px;
  width: 100%;
  line-height: 1;
  color: rgba(0, 0, 0, 0.8);
  content: "\25BC";
  position: absolute;
  text-align: center;
}

.d3-tip.n:after {
  margin: -1px 0 0 0;
  top: 100%;
  left: 0;
}