Using Reducer Functions in AEM Forms - Charts using-reducer-functions-in-aem-forms-charts

Reducer functions are used to aggregate or group values that are displayed in the chart.

For example, we can use the reducer functions to display the number of transactions per category, or display the highest expense per category from the sample data shown below

[{
"category": "Groceries",
"amount": 10
},
{
"category": "Groceries",
"amount": 20
},
{
"category": "Travel",
"amount": 100
},
{
"category": "Gas",
"amount": 500
},
{
"category": "Gas",
"amount": 80
},
{
"category": "Groceries",
"amount": 30
},
{
"category": "Travel",
"amount": 200
}
]

The following video walks through the steps involved in using reducer functions.

Transcript
In this video, we will take a look at using reducer functions in AEM forms. Reducer functions allow you to aggregate data displayed in a chart. Before we take a look at configuring or using reducer functions in AEM forms, let’s take a look at the simple form data model, which is going to be the basis for our interactive communications document. This form data model has a top level object called transactions, and this object has an association of one to n, or one to many with another entity called Expenses. This Expenses entity has two properties. One called Category and one called Amount. Now moving on to our interactive communications document, there are three chart objects added to this document, and each of these chart object is of type column here. These are the various chart types that you can define. So here we’re going to select column as our chart type, and the X axis is mapped to the category element of the form data model, and the Y axis is mapped to the amount element of the form data model. And then for the Y axis, we’re going to use a reducer function here. Reducer functions will always work on the data of the Y axis, so in this case, we are going to select frequency as our reducer function. These are the out of the box reducer functions that are available to you, when you install the product. So here I am going to select frequency as my reducer functions. I’m going to save my changes. Then in the second chart, again which is of type column, I’ve mapped the X and Y axis to the category and the amount element, and then the reducer function that I’m going to use is the maximum function. And then for the third chart, I’m going to use the sum function as my reducer function here. So I am going to select the sum function as my reducer function. I’m going to save those changes. So now you have configured your chart to use the appropriate reducer functions. Let’s take a look at run time with the data that is being used to render this chart. So the first one is the frequency category. So this tells you how many times an expense in a grocery category was made. In this case, it’s three. For travel it was two and for gas it was two. This one is the maximum expense in a particular category. So for gas, the maximum expense was 500 and with the third chart, it tells you the sum of all the expenses per category. So for gas it was 580, for travel it was 300, and for groceries it was 60. So this is how you would use reducer functions to aggregate data that are displayed in a chart in AEM forms. -
recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e