JSFiddle - React, Tailwind, and code Playground

by Fiddel

HTML

<script src="http://labratrevenge.com/d3-tip/javascripts/d3.tip.v0.6.3.js"></script>
<label><input type="checkbox">Sort</label><br>
<div id ="stackedChart">
<div id="legend"></div>

CSS

.div {
  font: 10px sans-serif;
}
.axis path,
.axis line {
  fill: none;
  stroke: #000;

}
.y.axis {
   font: 10px sans-serif;
}
.x.axis path {
  display: yes;
}
label {
  position: absolute;
  top: 10px;
  right: 250px;

}
.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;
}

/* Style northward tooltips differently */
.d3-tip.n:after {
  margin: -1px 0 0 0;
  top: 100%;
  left: 0;
}

JavaScript

var data = [{"moduleName":"module1","complete":"60","noncomplete":"40"},{"moduleName":"module2","complete":"50","noncomplete":"50"},{"moduleName":"module3","complete":"70","noncomplete":"30"},{"moduleName":"module4","complete":"60","noncomplete":"40"},{"moduleName":"module5","complete":"30","noncomplete":"70"},{"moduleName":"module6","complete":"70","noncomplete":"30"},{"moduleName":"module7","complete":"60","noncomplete":"40"},{"moduleName":"module8","complete":"50","noncomplete":"50"},{"moduleName":"module9","complete":"70","noncomplete":"30"},{"moduleName":"module10","complete":"60","noncomplete":"40"},{"moduleName":"module11","complete":"30","noncomplete":"70"},{"moduleName":"module12","complete":"70","noncomplete":"30"}]; 



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

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

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

var color = d3.scale.category20();

var xAxis = d3.svg.axis()
    .scale(x)
    .orient("bottom");

var yAxis = d3.svg.axis()
    .scale(y)
    .orient("left")
	.ticks(4)
    .tickFormat(function(d) { return d + "%"; });
	
var tip = d3.tip()
  .attr('class', 'd3-tip')
  .offset([-10, 0])
  .html(function(d) {
    console.log(d);
  console.log(d.name);
    return "<strong>Module:</strong> <span style='color:red'>" + d.name + "</span><br>"+
	"<strong>Compleated:</strong> <span style='color:steelblue'>" + d.y1 + "%</span><br>"+
	"<strong>Non Compleated:</strong> <span style='color:gray'>" + (100-d.y1) + "%</span>";
  })
 
var svg = d3.select("#stackedChart").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 + ")");
	
var svgLegend = d3.select("#legend").append("svg")
    .attr("width", 960)
    .attr("height",...