Search code examples
wolfram-mathematicabar-chartmathematica-8

How to stop barchart from hiding labels for data value 0 in Mathematica?


I use this to create a Bar Chart:

BarChart[
 Reverse@data,
 BarOrigin -> Left,
 ChartLabels -> 
  Placed[{Reverse@labels, Reverse@data}, {Before, After}],
 ChartElementFunction -> "FadingRectangle"
 ]

With data = {7, 10, 0, 6, 0, 3, 5} this gives

Mathematica graphics

The problem is that some of the data values are 0 and BarChart won't even add labels for them. Instead it leaves a open space. How can I get it to still add the labels even though the values are 0?

This is with Mathematica 8.


Solution

  • What about

    data = {7, 10, 0, 6, 0, 3, 5}
    
    labels = ("label " ~~ ToString[#]) & /@ data
    
    BarChart[Reverse@data, BarOrigin -> Left,
    ChartLabels -> Placed[{Reverse@labels, Reverse@data}, {Axis, After}],
    ChartElementFunction -> "FadingRectangle"]
    

    It seems that "Before" doesn't and "Axis" does work?

    chart