require(["esri/renderers/smartMapping/statistics/uniqueValues"], function(uniqueValues) { /* code goes here */ });
Function: esri/renderers/smartMapping/statistics/uniqueValues
Since: ArcGIS API for JavaScript 4.4

A function that queries for unique values from a field in a Layer.

Known Limitations

Method Overview

NameReturn TypeSummaryFunction
Promise<UniqueValuesResult>

Returns an object containing an array of unique values queried from a given field (or values returned from an expression) in a Layer along with the total count of features that belong to the given category.

more details
more detailsuniqueValues

Method Details

uniqueValues(params){Promise<UniqueValuesResult>}

Returns an object containing an array of unique values queried from a given field (or values returned from an expression) in a Layer along with the total count of features that belong to the given category.

Parameters:
params Object

See the table below for details of each parameter.

Specification:

The layer from which to query for unique values.

field String
optional

The name of the numeric or string field from which the unique values will be obtained. This property is ignored if a valueExpression is used.

valueExpression String
optional

An Arcade expression that returns a number or string. This expression can reference field values using the $feature global variable. This property overrides the field property and therefore is used instead of an input field value.

sqlExpression String
optional

A SQL expression evaluating to a number or string.

sqlWhere String
optional

A SQL where clause used to filter features for the statistics query. For example, this is useful in situations where you want to avoid dividing by zero as is the case with creating a predominance visualization.

returnAllCodedValues Boolean
optional

Indicates that all domain codes should be returned if the given field has domain values.

view View
optional

A SceneView or MapView instance is required when a valueExpression is specified.

features Graphic[]
optional

A subset of features for which to generate the unique values.

Returns:
TypeDescription
Promise<UniqueValuesResult>Returns a promise that resolves to UniqueValuesResult.
Example:
var layer = new FeatureLayer({
  portalItem: { id: "5ce5374a461e45bab714b43ffedf151d" }
});

uniqueValues({
  layer: layer,
  field: "Candidate"
}).then(function(response){
  // prints each unique value and the count of features containing that value
  var infos = response.uniqueValueInfos;
  infos.forEach(function(info){
    console.log("CANDIDATE: ", info.value, " # OF CAMPAIGN STOPS: ", info.count);
  });
});

Type Definitions

UniqueValuesResult

An object that contains the unique values returned from the uniqueValues() query of a layer's field.

Properties:
uniqueValueInfos Object[]

An array of objects, each containing a unique value/type/category present in the field specified in the uniqueValues() query. See table below for the specification of each object.

Specification:
value String | Number

A unique value representing a type or category of features in the layer.

count Number

The number of features assigned the given value (or belonging to the given category).

API Reference search results

NameTypeModule
Loading...