Learners and Educators

by skaggarwal

HTML

<!-- Code from d3-graph-gallery.com -->
<!DOCTYPE html>
<meta charset="utf-8">

<!-- Load d3.js -->
<script src="https://d3js.org/d3.v4.js"></script>

<!-- Create a div where the graph will take place -->
<div id="simple_bargraph"></div>

<div id="grouped"></div>

JavaScript

/* Simple Bar Graph

// set the dimensions and margins of the graph
var margin = {
    top: 30,
    right: 30,
    bottom: 70,
    left: 60
  },
  width = 460 - margin.left - margin.right,
  height = 400 - margin.top - margin.bottom;

// append the svg object to the body of the page
var svg = d3.select("#simple_bargraph")
  .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 + ")");

d3.csv("https://docs.google.com/spreadsheets/d/e/2PACX-1vRJQZHaIvFBxIHvux5n-8OVU7In21m7q-IkRidLr2fTD0lLoyOVdhJRgwmPSnN6gvgEJTW9-DY03dm-/pub?gid=1050706020&single=true&output=csv", function(data) {

  var x = d3.scaleBand()
    .range([0, width])
    .domain(data.map(function(d) {
      return d.Year;
    }))
    .padding(0.2);
  svg.append("g")
    .attr("transform", "translate(0," + height + ")")
    .call(d3.axisBottom(x))
    .selectAll("text")
    .attr("transform", "translate(10,0)")
    .style("text-anchor", "end");

  var y = d3.scaleLinear()
    .domain([0, 3500])
    .range([height, 0]);
  svg.append("g")
    .call(d3.axisLeft(y));
    
    svg.selectAll("mybar")
  .data(data)
  .enter()
  .append("rect")
    .attr("x", function(d) { return x(d.Year); })
    .attr("y", function(d) { return y(d.N); })
    .attr("width", x.bandwidth())
    .attr("height", function(d) { return height - y(d.N); })
    .attr("fill", "#69b3a2")

})
*/
// set the dimensions and margins of the graph
var margin = {
    top: 30,
    right: 30,
    bottom: 100,
    left: 60
  },
  width = 860 - margin.left - margin.right,
  height = 600 - margin.top - margin.bottom;

var svg_grouped = d3.select("#grouped")
  .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 +...