Friday, 2 May 2014

Stop X-Axis labels skipping values in SSRS

I came across an issue today involving a chart I’d added to a report. The chart was working as expected, but the values along the X-Axis were unclear, below is a screenshot of the graph with those values:
Graph Axis Label Issue
At a glance, the graph looks fine. Not until you take a good look at the values on the X-Axis do you see that there’s a problem. Spotted it? The values go from 1 to 4, and there’s a bar in between with no way of identifying if this is assigned to 2, 3, or both!
In order to resolve this, I went into the Axis Properties by clicking into the chart, right
clicking on the X-Axis, and selecting “Axis Properties…” at the very bottom of the list. This
will bring up the Category Axis Properties window, as below:
Graph Axis Properties
From this screen, tick “Scalar Axis” to force the axis to span all values that have data. For
example, if you have a chart with an X-Axis value of 1-5 available, and all of the available data falls in either 3 or 5, then 3, 4, and 5 will be displayed along the X-Axis, but not 1 and 2.
The result of ticking this box is now the below:
Graph Axis Label Issue Fixed
Much better! I can now see exactly which value each bar is assigned to. However, this has created another slight issue in that the values 0 and 11 are now displaying, even though the only available values for the X-Axis are 1 – 10. To get around this one, go back into the Axis Properties, but this time go to the second tab – “Labels”:
Graph Axis Labels Properties
Check “Hide first and last labels along this axis”. This will remove the first and last X-Axis
values from the list, so long as no data is assigned to them. In this example, no data will ever be assigned to 0 or 11, and will therefore be hidden – giving me exactly what I want:
Graph Axis Label Issue Fixed