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

17 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.

  1. Hi, how do you display just the percentage % symbol on already calculated Percentage Achieved field in Goals ? When I uses above specified label formats its calculating percentage of already calculated value instead I just want show ‘%’ symbol in chart beside the value. Any thoughts ?

  2. Hi,

    In my current project I would like to show percentage with Actual numbers. How I can do that?
    Currently I am using bar chart and I am able to show % sign on charts but as per requirement it should show % and actual value of that field.
    Please let me know how I can achieve that.

    thanks!
    Harsha

    • Hi Harsha. You will need to have two series and show one as the percentage and the other as the actual value. Another option, if you are not using the StackedBar is to use #VALY along with the #PERCENT in the label. What works best will depend on the chart type you are using.

      • HI Ulrik,

        Thank you so much for your reply.
        I am using Bar chart and I created three calculated fields for percentage calculations. I am using those fields on chart and adding percentage in their label. But I want to show % as well as value of the field which used to get percentage for ex: 85%(134999).
        I used your approach but I am getting 100%(134999). I used Label =”#PERCENT(#VALY)” this syntax.
        I am open for more suggestions or approaches.

  3. HI Ulrik,

    Thank you so much for your reply.
    I am using Bar chart and I created three calculated fields for percentage calculations. I am using those fields on chart and adding percentage in their label. But I want to show % as well as value of the field which used to get percentage for ex: 85%(134999).
    I used your approach but I am getting 100%(134999). I used Label =”#PERCENT(#VALY)” this syntax.
    I am open for more suggestions or approaches.

  4. Hello Ulrik, thank you for your post. I have a question about showing/calculating the percentage on a stacked bar chart (not a 100% one) in order to have the % of total margin(sum)/total revenue(sum), do you have any idea about how to achieve that ?
    Thank you and have a nice day.

  5. Hi, I am trying to to do a stacked bar chart showing actual vs. target per user. I have created a custom entity with user, phone actual, phone goal. so I can have a record for say User = Joe, Goal = 50, Actual = 15 (actual is a rollup field). I am creating 2 series (1 for actual and 1 for goal) and 1 category of user. when I look at the results, the actual number/chart takes up more space than the goal (they are the opposite of how I would expect them to be). Any help would be greatly appreciated.

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s