Stacked Bar Chart Labels - D3

后端 未结 1 1568
一整个雨季
一整个雨季 2021-01-15 14:37

I\'m trying to add data labels to stacked bar chart in d3.

I wanted the data labels to be in the middle of the bar. So far i just figured out how to add data labels

相关标签:
1条回答
  • 2021-01-15 15:19

    You just need to adjust the y coordinate of the text elements:

    circle.selectAll("text")
          .data(function(d) { return d.hours; })
          .enter()
          .append("text")
          .attr("x", 75)
          .attr("y", function(d, i) { return y(d.y1) + (y(d.y0) - y(d.y1))/2; })
          .style("text-anchor", "middle")
          .text("test")
    
    0 讨论(0)
提交回复
热议问题