Show values on top of bars in a barChart

前端 未结 5 1937
北恋
北恋 2020-12-03 15:47

I have a bar chart with ordinal scale for the x-axis. I want to display the y-values on the top of each bar or in the bottom of each bar. It would be also acceptable to disp

5条回答
  •  萌比男神i
    2020-12-03 16:16

    If you use a specialized valueAccessor with a chart, you can make the following substitution in dimirc's "D3-ish way" solution.

    Change

    .text(function(d){
        return d3.select(d).data()[0].data.value
    })
    

    To

    .text(function(d){
        return chart.valueAccessor()(d3.select(d).data()[0].data)
    });
    

提交回复
热议问题