Pie chart in report viewer 2010 (RDLC)

So you want a pie chart in your report? Well here are a few gotchas that are hard (at least to some of us :)) to understand how they work. Image illustrates 3 things that may catch you out – smart label line between pie slice and the label, percentage to be displayed as label and legend name as parameter or whatever else you need.

sample layout of a pie chart in VS2010 RDLC
Sample latyout of a pie chart VS2010 RDLC

Smart label refusing to show up

The key here is that the chart is made up numerous objects and as they all seem to contain the same names it becomes hard to know which one controls what.
The answer here lies in the chart object itself. Click on pie chart. Your current selection should now appear to be the first series of the pie chart. In the current property list find the “CustomAttributes” group. In here there are two values that you need to set the “PieLabelStyle” needs to be set to “Outside” and the “PieLineColor” needs to be set to whatever you need – just not default or auto (did not work for us until we set a specific color here). Lastly set the value of “Visible” to “True” and you’re done.

Percentage display on the label

This one is a little bit easier to find – for each series you display on the pie chart find the “Label” group and in here is a “Label” sub property which must be set to “#PERCENTAGE”. After this the number show will be in the format in the image above.

Legend text from parameter

Next we will discuss here is the label shown in the legend of the chart. This one is one of the gotchas of too many identically named fields – if you edit the “Legend” property “Text” nothing seems to happen. If that’s the case then select “DataPoint” next its “Legend” and lastly its “Text” property. Set it to say a parameter you’re passing e.g. “=Parameters!NameSeries1.Value”

The "right" Legend Text property
The “right” Legend Text property

RDLC Report – Divide by Zero ┬áproblem

Recently I came across a problem with one of the reports where under some rare circumstance the report would produce an “Error#” in the table. Upon inspection I have found that the expression used in the textbox was using a test IIF to determine if it could go ahead with a divide or not as in is the value 0 or not. The code was written intuitively as:

=IIf(Sum(Fields!Val4.Value) = 0, 0, Sum(Fields!Val3.Value)/Sum(Fields!Val4.Value))

Logically this should work but of course this doesn’t work for one simple reason – the interpreter of the report control takes all paramaters and evaluates them regardless of whether it will use them/needs or not. So how to solve this? It appears that doing a double IIF call will “shield” this operation hence the solution is to do the following:

=IIf(Sum(Fields!Val4.Value) = 0, "0%", Sum(Fields!Val3.Value) / IIf(Sum(Fields!Val4.Value) = 0, 1,Sum(Fields!Val4.Value)))

Since then I have found others who have come up with this issue back in 2006 – go figure that such a simple thing still exists and has not been fixed up in the later revisions of the report control.


That’s it for now!


Print Friendly, PDF & Email

One reply on “Pie chart in report viewer 2010 (RDLC)”

Comments are closed.