SSRS Line Chart Dynamic Y Axis

三世轮回 提交于 2019-12-04 13:05:30

Since you're using SSRS 2012, you can use the aggregate of an aggregate functionality to achieve this.

Say I have a chart like this, similar to yours:

With the appropriate data, it has the same issue as your screenshot, even with an expression in the Y-Axis interval:

i.e. here there are 8 rows, so the expression will be set to Auto, but because the groups have no more than three rows we get fractions in the Y axis.

We can get around this by finding the maximum of each of these group counts.

The Category Group will have a name:

Here I've called it MonthGroup. With this, we can change the Y Axis interval expression:

=IIf(Max(CountRows("MonthGroup")) <= 5, 1, Nothing)

i.e. if <=5, interval is 1, otherwise just pass a NULL value, i.e. let SSRS determine the interval.

So now we're checking the Max of the Category Group level CountRows; this is 3 in my example so now we're getting the required axis intervals:

Edit note:

Previously I had the Y Axis expression as:

=IIf(Max(CountRows("MonthGroup")) <= 5, 1, "Auto")

But after posting I noticed this was causing a warning in some circumstances; presumably because Auto is not a valid interval; it's just a placeholder used by SSRS. The updated expression:

=IIf(Max(CountRows("MonthGroup")) <= 5, 1, Nothing)

Works as expected without warnings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!