Common Pie Chart scenarios: Displaying numbers and percentages in a pie chart legend

Some formulas are used more often than others when building Klips. In this series of articles, a Klip is built using a common set of formulas to give a better understanding of how these formulas work within a sample data set.

The pie chart component allows you to compare individual values in relation to the whole.

In this example, the total values for each fruit type are displayed as a number and a percentage in the legend of a pie chart.

This article is rated Intermediate.

 

You can click the following link to download the sample data set for this Klip.

https://static.klipfolio.com/images/saas/answeredadvancedpiedata.xlsx

Summary of formulas

For the Values sub-component:

GROUPBY( A:A , B:B ) / SUM( B:B , data)...

For the Labels sub-component:

CONCAT( GROUP( A:A ), "(" , NUMBERFORMAT( GROUPBY( A:A , B:B , method ) , 0 , separator ) ")" , data )

Step 1: Building and configuring a pie chart

  1. Click the Build a New Klip button.
  2. Select the Pie Chart component.
  3. Select Use an existing data source form the library and select our sample data set.
  4. Select the Klip component and in the Properties panel, enter a name for the Klip Title.

Location

Action

For our example

With the Values sub-component selected, select the Data panel. Select Insert function, Data Manipulation, GROUPBY.
The GROUPBY function allows you to return a list of fruit types and sum related values.
GROUPBY( values , measure , method )
With values selected. Select column A , the column listing the fruit types. GROUPBY( A:A , measure , method )
With measure selected. Select column B, column listing the fruit values. GROUPBY( A:A , B:B , method ) ...
With ... selected. Select the mathematical operator /. GROUPBY( A:A , B:B ) / ...
With ... selected. Select Insert function, SUM. GROUPBY( A:A , B:B ) / SUM( data ) ...
With data selected. Select column B. GROUPBY( A:A , B:B ) / SUM( B:B , data )...

Location

Action

For our example

With the Labels sub-component selected, select the Data panel. Select Insert function, Data Manipulation, GROUP.
The GROUP function returns a unique list of fruit type names.
GROUP( values )
With values selected. Select column A, the column listing the fruit. GROUP( A:A )
In the formula editing toolbar, with the word GROUP selected. Select Wrap current value in function, Text, CONCAT.
The CONCAT function joins two values together.
CONCAT( GROUP( A:A ) data )
With data selected. Select the Insert literal string or number button and type space ( and click the Apply button. CONCAT( GROUP( A:A ), " (" , data )
With the Values sub-component selected. Copy the GROUPBY formula you created above using the keyboard combination Ctrl+C.  GROUPBY( A:A , B:B , method ) ...
With the Labels sub-component selected, in the formula editing toolbar, select data . Paste the GROUPBY formula you copied above using the keyboard combination Ctrl+V. CONCAT( GROUP( A:A ), "(" , GROUPBY( A:A , B:B , method ) , data )
With data selected. Select the Insert literal string or number button and type space ) and click the Apply button. CONCAT( GROUP( A:A ), "(" , GROUPBY( A:A , B:B ) , ")" , data)
In the formula editing toolbar, with the word GROUPBY selected. Select Wrap current value in function, Text, NUMBERFORMAT.
The function NUMBERFORMAT rounds the number from 60.0 to 60.
CONCAT( GROUP( A:A ), "(" , NUMBERFORMAT( GROUPBY( A:A , B:B , method) , precision , separator ) , ")" , data )
With precision selected. Select the Insert literal string or number button and type 0 (zero) and click the Apply button. CONCAT( GROUP( A:A ), "(" , NUMBERFORMAT( GROUPBY( A:A , B:B ) , 0 , separator ) , ")" , data )

Step 2: Setting property formats

  • Select the Values sub-component, Properties panel, for Format as, select Percentage.
  • Select the Labels sub-component, Properties panel, for Format as, select Text.

Step 3 : Setting the Pie Chart properties

  • Select the Pie Chart component, Properties panel, select an option for Size, Max Slices, Sort Order, and Labels.

Step 4: Troubleshooting

  • Use the Evaluate current selection button to verify that columns A and B contain the same number of items.
  • If the data source contains a row header, wrap all references to columns in the SLICE function. For more information, see Slice Function



Klip Tutorials

  1. Introduction
  2. Introduction to the Build-a-Klip Tutorial
  3. Build-a-Klip Tutorial: Phase One
  4. Build-a-Klip Tutorial: Phase Two
  5. Build-a-Klip Tutorial: Phase Three
  6. Build-a-Klip Tutorial: Phase Four
  7. Build-a-Klip Tutorial: Phase Five
  8. Example - Revenue YTD Klip
  9. Example - Financial Performance YTD Klip
  10. Example - World News Klip
  11. Example - Bookings by Country Klip
  12. Example - Bookings QTD Klip
  13. Example - Stock Quotes Klip
  14. Example - Marketing Traffic Sources Klip
  15. Example - 75/20 Service Level - Today Klip
  16. Training Klip - Array, Slice, Reverse, If, and Trim Functions
  17. Training Klip - Sum, Average, and Count Functions
  18. Training Klip - Group and Groupby Functions
  19. Training Klip - Date, Datevalue, and Today Functions
  20. Training Klip - Replace function and image URLs
  21. Training Klip - Concat and Join Functions
  22. Common Bar/Line Chart scenarios: Example of using the LOOKUP function with a condition to align data
  23. Common Bar/Line Chart scenarios: Example of using the LOOKUP function to align data
  24. Common User Input Control scenarios: Displaying total boxes of fruit sold in the last three months
  25. Common User Input Control scenarios: Counting all tickets by quarter, by month, by weekday
  26. Common Table scenarios: Selecting start and end dates to display number of boxes sold by country
  27. Common Table scenarios: Sorting data to display the video with the highest number of views
  28. Common Pie Chart scenarios: Displaying total number of surveys as a percentage by country
  29. Common Pie Chart scenarios: Displaying numbers and percentages in a pie chart legend

Feedback and Knowledge Base