Add Percentage Labels to a 100% Stacked Bar chart in MS Dynamics CRM

The 100% stacked bar chart is great to display the relative amounts within a series.

However, for some reason the 100% stacked bar chart comes without labels to indicate what the percentage is for each group. You can eyeball it, but that’s not very accurate.

Original StackedBar100 chart
A 100% stacked bar chart made in the MS Dynamics CRM chart editor. No labels.

It is a little tricky to get to the accurate result, so I will go through the process of getting there.

The obvious thing to try first, is to export the chart xml and add IsValueShownAsLabel=”True” to the series.

        <Series ChartType="StackedBar100" IsValueShownAsLabel="True" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40">
          <SmartLabelStyle Enabled="True" />
        </Series>

 

IsvalueShownAsLabel True on a StackedBar100 chart
IsValueShownAsLabel=”True” added. Labels are the sum of the group.

This gives us the sum of each individual phase. This could be useful in its own right, but I really want the percentage on the label.

The next obvious thing to try, is to put in Label=”#PERCENT” and set IsValueShownAsLabel=”False”. Why not? It works great for pie charts.

        <Series ChartType="StackedBar100" IsValueShownAsLabel="False" Label="#PERCENT" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40">
          <SmartLabelStyle Enabled="True" />
        </Series>

 

Keyword PERCENT on StackedBar100 chart
Keyword Label=”#PERCENT” added. The percentages run across the bars rather than within a single bar.

Now we get some great looking percentages, but the values add up to 100 on the second series. Not across like we would expect.

The magic combo to add to the series xml for percentage labels on a 100% stacked bar chart in MS Dynamics CRM is:

IsValueShownAsLabel=”True” LabelFormat=”#.00′ %'”

        <Series ChartType="StackedBar100" IsValueShownAsLabel="True" LabelFormat="#.00' %'" Font="{0}, 9.5px" LabelForeColor="59, 59, 59" CustomProperties="PointWidth=0.75, MaxPixelPointWidth=40">
          <SmartLabelStyle Enabled="True" />
        </Series>

 

StackedBar100 chart with correct percentages as labels in Microsoft Dynamics CRM charts.
With IsValueShownAsLabel=”True” and LabelFormat added, the percentages on the labels now display as intended.

Finally we have proper percentages across on the bar chart as we would expect.

 

A couple of other optimizations for a percentage bar chart.

LabelFormat=”#.00 ‘%'” in the series to show the percentage sign and always have 2 decimals.

Format=”0’%'” on the Y-axis to remove decimals and add percentage sign.

More on where and how to add Format and LabelFormat in MS Dynamics CRM charts here.

Thank you for reading. Please sign up for the newsletter to stay up to date on new blog posts and follow me on Twitter

9 thoughts on “Add Percentage Labels to a 100% Stacked Bar chart in MS Dynamics CRM

      • Here is the error log:
        Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: PresentationDescription is invalid and cannot be loaded. Message: Cannot deserialize property. Unknown property name ‘IsValueShowAsLabel’ in object ” System.Web.UI.DataVisualization.Charting.SeriesDetail:

        -2147164138

        0
        PresentationDescription is invalid and cannot be loaded. Message: Cannot deserialize property. Unknown property name ‘IsValueShowAsLabel’ in object ” System.Web.UI.DataVisualization.Charting.Series

        PresentationDescription is invalid and cannot be loaded. Message: Cannot deserialize property. Unknown property name ‘IsValueShowAsLabel’ in object ” System.Web.UI.DataVisualization.Charting.Series
        2016-09-01T14:07:11.0706653Z

      • IsValueShowAsLabel is in your error message
        IsValueShownAsLabel is how the property should look

        Generally, the “Unknown property name” error messages are usually always typos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s