Maximum width for column in bar chart

后端 未结 6 1059
天命终不由人
天命终不由人 2021-02-14 09:35

I\'m looking for a way of limiting the column width in a chart, I\'m sure this ought to be relatively easy but I cant find a way of doing it.

I\'m populating a chart fro

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-14 10:00

    For completeness the full answer would look like this:

    svg.selectAll(".bar")
      .data(data)
      .enter().append("rect")
      .attr("class", "bar")
      .attr("x", (d) -> x1(d.name) + (x1.rangeBand() - d3.min([x1.rangeBand(), 100]))/2)
      .attr("width", d3.min([x1.rangeBand(), 100]))
      .attr("y", (d) -> y(d.grade) )
      .attr("height", (d)-> height - y(d.value) )
    

    (coffeescript syntax)

    Note this include the full answer, the 'width' and the 'x' settings. Also 'x' settings is accounting for a when 100 width is not the min value.

提交回复
热议问题