charts

Certified Senior Developer

hello ,

 

Working on the aggregate data from a data store entity by multiple fields and display in a column chart. For some reason ,following error message is displayed.By looking into the error message ,something is not working with the variable I used for  grouping and showing error at forEach. could you please look into the error message and let me know whether something need to be corrected. 

error message :

 Interface Definition: Expression evaluation error at function a!forEach [line 66]: Invalid function a!forEach (not available as [])

 .

=load(
  /* 
  * Paginginfo is bringing back all employee data in this case and sorting by
  * department.
  */
  local!pagingInfo: a!pagingInfo(
    startIndex: 1,
    batchSize: -1,
    sort: a!sortInfo(
      field: "source",
      ascending: true
    )
  ),
  with(
   /* 
    * local!datasubset is pulling data from the employee data store entity 
    * from the entity backed record tutorial The resulting data value looks 
    * like this data: { {department:Engineering, title:Director id: 1}...}
    *
    * To use your data, change the constant from cons!EMPLOYEE_ENTITY to one of
    * your own. Then replace the fields in the queryAggregationColumns to a
    * relevant datapoint from your data store entity
    */
    local!datasubset: a!queryEntity(
      entity: cons!DQ_Cons_log,
      query: a!query(
        aggregation: a!queryAggregation(
         aggregationColumns: {
          a!queryAggregationColumn(field: "source", isGrouping: true),
          a!queryAggregationColumn(field: "status", isGrouping: true),
          a!queryAggregationColumn(field: "IncId", aggregationFunction: "COUNT")
         }
        ),
        pagingInfo: local!pagingInfo
      )
    ),
    /* 
    * local!categories is returning all department values. local!uniqueDepartments
    * is reducing the list down to only unique values. This populates the column
    * chart categories.
    *
    * To use your data, change the second parameter in the index function from
    * "department" to whatever data point is going to be your category
    */
    local!categories: index(local!datasubset.data, "department", {}),
    local!uniqueCategories: union(local!categories, cast(typeof(local!categories), {})), 
    /* 
    * local!labels and local!uniqueLabels provide the name of each piece in the
    * column.
    *
    * To use your data, change the second parameter in the index function from
    * "title" to whatever data point is going to be the label of each piece
    */
    local!labels: index(local!datasubset.data, "title", {}),
    local!uniqueLabels: union(local!labels, cast(typeof(local!labels), {})),
    /* 
    * local!series puts everything together for the column chart. It runs through
    * two a!forEach() loops. The first loop will lopp over a list of categories to
    * find matching data, while the second a!forEach() loop will find all matching
    * datapoints in that category.
    *
    * To use your data, change the second parameter in the index function at the
    * end of the second a!forEach() loop. Replace "id" to whatever data point is 
    * providing the numeric value to count on in your dataset.
    */
    local!series:a!forEach(
        items:local!uniquelabels,
        expression: with(
          local!label:fv!item,
           a!chartSeries(
            label: local!label,
            /* Loops over list of categories to find each datapoint that matches  
             * the series label and the category. This will ensure that the 
             * datapoints are in the correct order to display in the chart.                       
             */
            data: a!forEach(
              items:local!uniqueCategories,
              expression: with(
              /* Find all datapoints that match both the category and chart series label   */
                local!intersection: intersection(
                  where(local!categories=cast(typeof(local!categories), fv!item), 0),
                  where(local!labels=cast(typeof(local!labels), local!label), 0)
                ),
                if(
                length(local!intersection)=0,
                /* If there is no datapoint for this category-label pair, return 0 
                 * so that all subsequent points are in the correct order with the 
                 * categories.      
                 */
                0,
                index(index(local!datasubset.data, "incId", {}), local!intersection, 0)
                )
              )
            )
          )
        )
     ),
    a!columnChartField(
      categories: local!uniqueCategories,
      series: local!series,
      xAxisTitle: "Departments",
      yAxisTitle: "Number of log",
      stacking: "NORMAL"
    )
  )
)

  Discussion posts and replies are publicly visible

Parents Reply Children
No Data