score:1

Accepted answer

You can create a simple line chart and use d3.curveBasis or any other interpolation you like. Play with the data to get the desired result.

Here's the snippet:

var margin = {
  top: 30,
  right: 20,
  bottom: 30,
  left: 50
};
var width = 550 - margin.left - margin.right;
var height = 150 - margin.top - margin.bottom;


var x = d3.scaleLinear().range([0, width]);
var y = d3.scaleLinear().range([height, 0]);

var valueline = d3.line()
  .x(function(d) {
    return x(d.x);
  })
  .y(function(d) {
    return y(d.y);
  }).curve(d3.curveBasis);

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 + ")");

var data = [{
  x: 1,
  y: "0"
}, {
  x: 1.05,
  y: "0.6"
}, {
  x: 3,
  y: "1.3"
}, {
  x: 4.95,
  y: "0.6"
}, {
  x: 5,
  y: "0"
}];

data.forEach(function(d) {
  d.x = d.x
  d.y = +d.y;
});


x.domain(d3.extent(data, function(d) {
  return d.x;
}));
y.domain([0, d3.max(data, function(d) {
  return d.y;
})]);

svg.append("path")
  .attr("d", valueline(data));
path {
  stroke: black;
  stroke-width: 8;
  fill: none;
  stroke-linecap: round;
  shape-rendering: geometricprecision;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.13.0/d3.min.js"></script>


More Query from same tag