<h2> NBA Draft Position / Year </h2>
<svg id="chart"></svg>
@import url('https://fonts.googleapis.com/css?family=Roboto+Condensed:400,700');
body {
  font-size: 16px;
  font-family: "Roboto Condensed", sans-serif;
}

h2 {
  font-family: "Roboto Condensed", sans-serif;
  font-weight: 700;
  margin-bottom: 0;
}

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

.circle {
  fill: #0074D9;
  fill-opacity: 0.9;
}

.pos-1 {
  fill: #F012BE;
}

.pos-61 {
  fill: #F012BE;
}

#tooltip {
  position: absolute;
  left: -1000px;
  top: -1000px;
  width: 190px;
  height: 20px;
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
  background-color: rgba(128, 128, 128, 0.8);
  color: #FFF;
}
const url = 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/156286/nba-draft-position-year.csv';
const margin = {top: 40, right: 0, bottom: 60,left: 30};
const width = 680, height = 500;

const tooltip = d3.select('body').append('div').attr('id', 'tooltip');
const x = d3.scaleLinear().range([0, width]);
const y = d3.scaleLinear().range([height, 0]);

const chart = d3.select('#chart')
  .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(url).get((data) => {
  
    x.domain( [1997, 2017] );
    y.domain([62, 1]);
  
    chart.append('g')
      .attr('transform', `translate(0,${height})`)
      .call(d3.axisBottom(x).ticks(7).tickFormat(d3.format("Y")));
    
    chart.append('text')             
      .attr('transform', `translate(${width/2},${height + margin.top})`)
      .attr('id', 'x-label')
      .text('Year');

    chart.append('g')
      .call(d3.axisLeft(y).tickValues([1].concat(y.ticks())));
     
    chart.selectAll('.circle')
      .data(data)
      .enter().append('circle')
      .attr('class', (d) => 'circle pos-'+d.Pos)
      .attr('cx', (d) => x(d.Year))
      .attr('cy', (d) => y(d.Pos))
      .attr('r', 6)
      .on('mouseover', (d) => {
        tooltip.transition()
          .duration(100)    
          .style('opacity', 1.0);
        tooltip.text(`${d.Player} #${d.Pos} (${d.Year})`)
          .style('left', `${d3.event.pageX - 75}px`)  
          .style('top', `${d3.event.pageY + 18}px`);
      })
      .on('mouseout', () => {   
        tooltip.transition()    
        .duration(400)    
        .style('opacity', 0); 
      });
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/d3/4.5.0/d3.min.js