Build a Pie Chart - maneeshpal/Drata GitHub Wiki

The way data is segmented does not differ between Pie and Bar chart, although Bar chart is capable of displaying more groups than Pie Chart.

To simplify the visualization, Drata displays a single Pie Chart per visualization. If your query ends up generating data that needs more than one Pie Chart to be visualized, each of those Pie charts can be toggled with the dropdown shown on the Widget.

This view you see below is the Widget Editor view. All the important functionalites are marked with bullet points.

  1. Selections: The properties that you select to visualize. In the above illustration, the user selected two properties, price and discount. Every selection can be a composed of other nested selections. For example select sum(price), sum(price - discount) etc..See more about Selections

  2. GroupBy :You can specify upto two levels of GroupBy. In the example illustration, the results are first grouped by sex, which splits the data into 2 different sets, one for Male and one for female. Since there are 2 selections to take care of, and the widget is designed to visualize a single pie chart at a time, only the pie chart resulting in Sum of Price for Male is displayed. Three more selections sum of Price -> female, sum of Discount -> male,sum of Discount -> female are behind the dropdown list shown at #5.

  3. GroupBy level 2 : Now here is the tricky part. Drata knows that there are two selections, and on top of that, those selections are grouped by Sex and later by ItemAgeGroup. So, now each selection is assigned a group based on value of Sex (male, female). Each of these groups is then grouped by ItemAgeGroup and aggregate functions are applied to the value of selections as specified. This results in 4 Pie Charts : (2 selections (price, discount) * 2 (male, female)). Each of those pie charts will show the aggregate result of selection, grouped by ItemAgeGroup as shown in #7.

  4. You need to specify a numeric or date interval depending upon whether you are grouping results using date/numeric properties. Since in this illustration, we are grouping by properties of type string, no interval is required. See more about Date Interval

  5. If your query results in multiple visualizations, this dropdown shows up, giving you the ability to toggle between those visualizations.

  6. Labels that distinguish between the groupings resulted via GroupBy, GroupBy level2 in #2 and #3. If there is no GroupBy level 2, these labels will show the values of GroupBy property.

  7. Same as #6.

Query Resulting Visualization
1 selection, with no GroupBy and no GroupBy level 2
Pretty much basic, you can visualize the count, avg, sum of the selection.
1 Pie Chart with 1 slice
Figure 2.1
Grouping the above chart by Geography Figure 2.2
1 selection, grouped by sex and then each of those groups is grouped by Geography
sum aggregate function is applied on Price for each geography. Each of these groups is further grouped by sex. This results in 2 pie charts. count(price) for female and count(price) for male, where male and female correspond to the values of Sex
	</td>
	<td>[[images/widgets/pie/pie_1s_1g_1g2.png]]
	<em>Figure 2.3</em></td>
</tr>
<tr>
	<td>
		<h6>2 properties (<em>price, discount</em>) are selected for visualization without any <em>GroupBy</em></h6>
		For Pie chart, inorder to compare the two properties selected, Drata requires you to apply aggregate functions over those selections.
		You will see the same approach in [[Building a Bar Chart]]
	</td>
	<td>[[images/widgets/pie/pie_2s_0g_0g2.png]]
	<em>Figure 2.4</em></td>
</tr>
<tr>
	<td>
		<h6>2 selections are selected for visualization grouped by <em>Sex</em></h6>
		This is same as <em>Figure 2.2</em>, except for we have selected 2 properties <em>Price, discount</em> to visualize, resulting in 2 pie charts that can be toggled by a dropdown.
	</td>
	<td>[[images/widgets/pie/pie_2s_1g_0g2.png]]
	<em>Figure 2.5</em></td>
</tr>
<tr>
	<td>
		<h6>2 selections grouped by <em>Sex</em> and then each of those groupes is grouped by <em>Geography</em> </h6>
		The resulting Pie Charts will be similar to Figure 2.3, except for this time, we have more than one property <em>Price, Discount</em> to visualize.
		We have 2 selections, which are grouped by <em>Sex</em>, resulting in 4 pie charts that can be toggled using a dropdown as shown in the illustration.

		1. <em>Sum of Price for female</em>
		2. <em>Sum of Price for male</em>
		3. <em>sum of Discount for female</em>
		4. <em>Sum of Discount for male</em>

		Each of these pie charts will have slices based on values of the second <em>GroupBy level 2</em> property as shown in the labels. 
	</td>
	<td>[[images/widgets/pie/pie_2s_1g_1g2.png]]
	<em>Figure 2.6</em></td>
</tr>
⚠️ **GitHub.com Fallback** ⚠️