D3.js add label to bar chart

前端 未结 1 1612
夕颜
夕颜 2021-01-25 06:32

How can I add label to a bar chart? The bar chart extends along the x-axis and I want to append the labels along the y-axis.

I read some examples and they use an extern

相关标签:
1条回答
  • 2021-01-25 07:02

    You can get the value of your label by the index like this :

     bar.append("text")
              .attr("x", function(d) { return x(d) - 3; })
              .attr("y", barHeight / 2)
              .attr("dy", ".35em")
              .text(function(d, i) { return label[i]; });
    
    0 讨论(0)
提交回复
热议问题