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

Only FeatureLayer, SceneLayer, and PointCloudLayer layer types are supported, except in the following scenarios:

  • FeatureLayers created with source graphics or feature collections.
  • SceneLayers without the supportsRenderer and supportsLayerQuery capabilities enabled, unless a predefined statistics object is passed to the statistics parameter of the method in conjunction with the layer. To check a SceneLayer's capabilities, use the getFieldInfoUsage() method.

Method Overview

NameReturn TypeSummaryFunction
Promise<UniqueValuesResult>

Returns an object containing an array of unique values queried from a given field 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 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

The name of the numeric or string field from which the unique values will be obtained.

features Graphic[]
optional

If the layer is a FeatureLayer constructed with client-side graphics or you would like to calculate statistics based on a subset of features, then pass the features in this parameter.

returnAllCodedValues Boolean
optional

Indicates that all domain codes should be returned if the given field has domain 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 specifed 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

There were no match results from your search criteria.