Skip to main content
September 20, 2022
Solved

Generate a Pie chart with expression rule

  • September 20, 2022
  • 4 replies
  • 0 views

Hi,

I need to create a pie chart with the output from expression rule.

I can use a!queryEntity() if the output is in Datastore entity with the help of aggregation functions.

Can anyone help me how to store the expression rule output to Data store entity or how to use the rule output directly in pie chart creation.

Thanks in advance.

    Best answer by ujjwalr0002

    You can use the output directly by indexing your data from the query rule and applying loop on the chart series and again indexing the labels and counts.

    4 replies

    Participating Frequently
    September 20, 2022

    You can use the output directly by indexing your data from the query rule and applying loop on the chart series and again indexing the labels and counts.

    Participating Frequently
    September 20, 2022

    In case you are not clear with the above answer please refer to the code below.

    a!localVariables(
      local!selectedDepartment,
      /* This query fetches the grouped data for the pie chart. */
      local!chartDatasubset: a!queryEntity(
        entity: cons!EMPLOYEE_ENTITY,/*entity name */
        query: a!query(
          aggregation: a!queryAggregation(
            aggregationColumns: {
              a!queryAggregationColumn(
                field: "department",
                isGrouping: true
              ),
              a!queryAggregationColumn(
                field: "id",
                alias: "id_count",
                aggregationFunction: "COUNT"
              )
            }
          ),
          pagingInfo: a!pagingInfo(
            startIndex: 1,
            batchSize: -1,
            sort: a!sortInfo(
              field: "department",
              ascending: true
            )
          )
        )
      ),
      {
        a!pieChartField(
          series: a!forEach(
            items: local!chartDatasubset.data,
            expression: a!chartSeries(
              label: fv!item.department,
              data: fv!item.id_count,
              /* Clicking on the chart sets the filter value for the grid. */
              links: a!dynamicLink(value: fv!item.department, saveInto: local!selectedDepartment)
            )
          ),
          showWhen: isnull(local!selectedDepartment), 
          colorScheme: "MOSS",
          style: "DONUT"
        )
      }
    )
    

    September 20, 2022

    Thanks Ujjwal, I was able to generate the report