0
votes

So, I've got this bar chart and I need to label the bars, but some are positive and some are negative. I've got the negative ones covered...

http://randomness.s3.amazonaws.com/bar_labels.html

enter image description here

For the bars that are positive, how can I shift those labels to be at the end of the bar without affecting the negative value bar labels?

Is this even possible?

1

1 Answers

0
votes

Use an if statement when setting your x attribute:

.attr("x", function(d, i) { 
    if (d.value <= 0) {return  x(Math.min(0, d.value)) - 15;}
    else {return  x(Math.min(0, d.value)) + Math.abs(x(d.value) - x(0)) + 1;}
})

as in http://jsfiddle.net/qAHC2/141/