JSFiddle - React, Tailwind, and code Playground

by dm89

HTML

<link rel="stylesheet" href="nv.d3.css">
<script src="nv.d3.min.js"></script>
<div id="chart">
  <svg></svg>
</div>

CSS

#chart svg {
  height: 600px;
}

JavaScript

function getData(groups, points) {
  var data = [],
      shapes = ['circle', 'cross', 'triangle-up', 'triangle-down', 'diamond', 'square'],
      random = d3.random.normal();

  for (i = 0; i < groups; i++) {
    data.push({
      key: 'Group ' + i,
      values: []
    });

    for (j = 0; j < points; j++) {
      data[i].values.push({
        x: random() + 3
      , y: Math.floor(Math.random() * 33) 
      , size: Math.random()
      //, shape: shapes[j % 6]
      });
    }
  }

  return data;
}

//nv.addGraph(function() {
  var chart = nv.models.scatterChart()
                .showDistX(true)
                .showDistY(true)
                .xDomain([0,3])
              
                .color(d3.scale.category10().range());

  chart.xAxis.tickFormat(d3.format('.02f'));
  chart.yAxis.tickFormat(d3.format('.02f'));
  chart.yAxis.tickValues(['2','4','8','16','32']);

var data = getData(4,40);
var x = d3.scale.linear().domain([0, data.length]);//.range([0, 600]);


  d3.select('#chart svg')
      .datum(getData(4,40))
    .transition().duration(500)
      .call(chart);

d3.select('#chart svg').append('line')
.attr({
    x1: x(0), // x() is your scaling function, 10 is the value where you want a line to be placed
    y1: 10, // height of your chart
    x2: x(3), // same as x1 for a horizontal line
    y2: 10 // height of your chart
});

  nv.utils.windowResize(chart.update);

   
  //return chart;
//});