D3.js Template

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="//d3js.org/d3.v4.min.js"></script>
<div class="chart"></div>

CSS

* {
  margin: 0;
  padding: 0;
  border: 0;
}

body {
  background: #ffd;
} 

.line {
  fill: none;
  stroke: steelblue;
  stroke-width: 2px;
}

body { font: 12px Arial;}

.legend {
    font-size: 16px;
    font-weight: bold;
    text-anchor: left;
}

JavaScript

var $this = $('.chart');

        var data = [{
          "date": "1-May-12",
          "close": 20
        }, {
          "date": "27-Apr-12",
          "close": 10
        }, {
          "date": "30-Apr-12",
          "close": 45
        }, {
          "date": "17-Apr-12",
          "close": 11
        }, {
          "date": "3-Apr-12",
          "close": 75
        }, {
          "date": "2-Apr-12",
          "close": 1
        }];

//https://bl.ocks.org/d3noob/ced1b9b18bd8192d2c898884033b5529

// set the dimensions and margins of the graph
var margin = {top: 20, right: 150, bottom: 30, left: 50},
    width = 960 - margin.left - margin.right,
    height = 470 - margin.top - margin.bottom;

// array of curve functions and tites

var curveArray = [
    {"d3Curve":d3.curveLinear,"curveTitle":"curveLinear"},
    {"d3Curve":d3.curveStep,"curveTitle":"curveStep"},
    {"d3Curve":d3.curveStepBefore,"curveTitle":"curveStepBefore"},
    {"d3Curve":d3.curveStepAfter,"curveTitle":"curveStepAfter"},
    {"d3Curve":d3.curveBasis,"curveTitle":"curveBasis"},
    {"d3Curve":d3.curveCardinal,"curveTitle":"curveCardinal"},
    {"d3Curve":d3.curveMonotoneX,"curveTitle":"curveMonotoneX"},
    {"d3Curve":d3.curveCatmullRom,"curveTitle":"curveCatmullRom"}
  ];
  

// parse the date / time
var parseTime = d3.timeParse("%d-%b-%y");

// set the ranges
var x = d3.scaleTime().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);

// define the line
var valueline = d3.line()
    .curve(d3.curveCatmullRomOpen)
    .x(function(d) { return x(d.date); })
    .y(function(d) { return y(d.close); });

// append the svg obgect to the body of the page
// appends a 'group' element to 'svg'
// moves the 'group' element to the top left margin
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 +...