Skip to content Skip to sidebar Skip to footer

How Do I Plot Multiple Rectangles On The Same Plot In D3

I am trying to create multiple rectangles on a single plot using data from a csv file. With my current approach, I am appear to be creating multiple plots per each row of data. I s

Solution 1:

Read thinking with joins, what you're doing is creating multiple svg nodes instead of a single svg with multiple rects

d3.csv('Input/test_single.csv')
  .row(function (d) { return d })
  .get(function (error, rows) {
    var chart = d3.select("#chart-div").append('svg').classed("chart", true).attr("width", width)

    chart.selectAll('rect').data(rows)
      .enter()
      .append("rect")
      .attr("x", function(d){return(parseInt(d.Start) + parseInt(spacer))})
      .attr("y", 75)
      .attr("width", function(d){return(parseInt(d.End) - parseInt(d.Start))}) 
      .attr("height", 50)
      .style("stroke", "rgb(255,0,0)")
      .style("stroke-width", 2)
});

Post a Comment for "How Do I Plot Multiple Rectangles On The Same Plot In D3"