Maximum width for column in bar chart

后端 未结 6 1056
天命终不由人
天命终不由人 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 09:40

    I am able to change the width of the bar using the above answer. But unfortunately, my X Axis labels are not aligned when there is a single bar in the chart and it uses the max width set.

    var tradeGroup = svg.selectAll("g.trade")
                .data(trades)
                .enter()
                .append("svg:g")
                .attr("class", "trade")
                .style("fill", function (d, i) {
                    return self.color(self.color.domain()[i]);
                })
                .style("stroke", function (d, i) {
                    return d3.rgb(self.color(self.color.domain()[i])).darker();
                });
    
    var aWidth = Math.min.apply(null, [x.rangeBand(), 100]);
    
    // Add a rect for each date.
    var rect = tradeGroup.selectAll("rect")
                .data(Object)
                .enter()
                .append("svg:rect")
                .attr("x", function (d) {                 
                    return x(d.x);
                })
                .attr("y", function (d) { return y( (d.y || 0) + (d.y0 || 0)); })
                .attr("height", function (d) { return y(d.y0 || 0) - y((d.y || 0) + (d.y0 || 0)); })
                .attr("width", Math.min.apply(null, [x.rangeBand(), 100]));
    

提交回复
热议问题