Free cookie consent management tool by TermsFeed

Aggregate Data and Display in a Chart

Tip:  Interface patterns give you an opportunity to explore different interface designs. Be sure to check out How to Adapt a Pattern for Your Application.

Goal

Aggregate data, specifically the total number of employees in a given department, to display in a pie chart.

Note:  This expression uses direct references to the Employee record type, created in the Records Tutorial. If you've completed that tutorial in your environment, you can change the existing record-type references in this pattern to point to your Employee record type instead.

image of a pie chart with 5 slices

This scenario demonstrates:

  • How to aggregate data and display in a pie chart.

Create this pattern

You can easily create this pattern in Design Mode when you use a record type as the source of your chart.

To create this pattern in Design Mode:

  1. Open a new or empty interface object.
  2. From the PALETTE, drag a Pie Chart component into the interface.
  3. From Data Source, select RECORD TYPE and search for the Employee record type.
  4. Under Primary Grouping, select the department field.
  5. Under Measure, use the dropdown to select Count of, then select the id field.
  6. Under Style, use the dropdown to select Pie.

Your resulting expression will look something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  a!pieChartField(
    data: recordType!Employee,
    config: a!pieChartConfig(
      primaryGrouping: a!grouping(
        field: recordType!Employee.fields.department,
        alias: "department_primaryGrouping"
      ),
      measures: {
        a!measure(
          function: "COUNT",
          field: recordType!Employee.fields.id,
          alias: "id_count_measure1"
        )
      },
      dataLimit: 100
    ),
    label: "Pie Chart",
    labelPosition: "ABOVE",
    colorScheme: "CLASSIC",
    style: "PIE",
    seriesLabelStyle: "ON_CHART",
    height: "MEDIUM",
    refreshAfter: "RECORD_ACTION"
  )
}

Notable implementation details

Feedback