import histogram from "@arcgis/core/smartMapping/statistics/histogram.js";
const histogram = await $arcgis.import("@arcgis/core/smartMapping/statistics/histogram.js");
@arcgis/core/smartMapping/statistics/histogram
Generates a histogram based on data in a Layer for a given field. The returned object can be used for displaying a histogram in the UI within visualization authoring applications and analytical apps that query and display statistics.
Known Limitations
- SceneLayers must have the
supportsRendererandsupportsLayerQuerycapabilities enabled unless a predefined statistics object is provided to thestatisticsparameter of the method. To check a SceneLayer's capabilities, use the getFieldUsageInfo() method. - You cannot generate statistics using SQL expressions for client-side FeatureLayers in a SceneView.
- The
normalizationTypeparameter only normalizes data returned by afield. It does not apply to values returned from avalueExpressionorsqlExpression.
Method Overview
| Name | Return Type | Summary | Function |
|---|---|---|---|
Promise<HistogramResult> | Generates a histogram for data returned from a | histogram |
Method Details
-
histogram
Methodhistogram(params){Promise<HistogramResult>} -
Generates a histogram for data returned from a
fieldin a givenlayer. The returned object can be used for displaying a histogram to the UI in visualization authoring applications and analytical apps that query and display statistics.ParametersSpecificationparams ObjectSee the table below for details on parameters that may be passed to this function.
Specificationlayer FeatureLayer|SceneLayer|CSVLayer|ParquetLayer|PointCloudLayer|GeoJSONLayer|WFSLayer|OGCFeatureLayer|StreamLayer|OrientedImageryLayer|CatalogFootprintLayer|CatalogLayer|KnowledgeGraphSublayer|SubtypeGroupLayer|SubtypeSublayer|ImageryLayerThe layer for which to generate a histogram. When a client-side layer type is provided, attribute and spatial statistics are calculated only from features in the view's extent. When a server-side layer type is provided, the statistics are calculated from the entire layer, unless a
valueExpressionis provided.field StringoptionalThe name of the numeric field for which the histogram will be generated. This property is ignored if a
valueExpressionis used.normalizationType StringoptionalDetermines how the provided
fieldvalues will be normalized. This parameter only normalizes data referenced by afield, and does not apply to values returned from avalueExpressionorsqlExpression. See the table below for a list of possible values.Possible Value Description field Divides the data value using the value of the field specified in the normalizationFieldparameter. AnormalizationFieldmust be provided if this value is used.percent-of-total Divides the data value by the sum of all data values then multiplies by 100. Use normalizationTotalto define the total value by which to normalize.log Computes the base 10 logarithm of the data values. This can be a useful approach for viewing highly skewed data distributions because it reduces the influence of outliers. Only positive values are computed. You should avoid this normalization type if your data contains a significant number of negative values. natural-log Computes the natural logarithm of the data values. This can be a useful approach for viewing highly skewed data distributions because it reduces the influence of outliers. Only positive values are computed. You should avoid this normalization type if your data contains a significant number of negative values. square-root Computes the square root of the data values. This can be a useful approach for viewing highly skewed data distributions because it reduces the influence of outliers. Only positive values are computed. You should avoid this normalization type if your data contains a significant number of negative values. Possible Values:"field"|"log"|"percent-of-total"|"natural-log"|"square-root"
normalizationField StringoptionalThe field by which to normalize the values returned from the given
field.normalizationTotal NumberoptionalOnly applies if
normalizationTypeispercent-of-total. Indicates the total amount with which to normalize field values.classificationMethod StringoptionalThe method for classifying the data. See the table below for a list of possible values.
Possible Value Description natural-breaks Data values that cluster are placed into a single class. Class breaks occur where gaps exist between clusters. You should use this method if your data is unevenly distributed; that is, many features have the same or similar values and there are gaps between groups of values. equal-interval Each class has an equal range of values; in other words, the difference between the high and low value is equal for each class. You should use this method if your data is evenly distributed and you want to emphasize the difference in values between the features. quantile Each class has roughly the same number of features. If your data is evenly distributed and you want to emphasize the difference in relative position between features, you should use the quantile classification method. If, for example, the point values are divided into five classes, points in the highest class would fall into the top fifth of all points. standard-deviation Class breaks are placed above and below the mean value at intervals of 1,0.5, or0.25standard deviations until all the data values are included in a class.Possible Values:"equal-interval"|"natural-breaks"|"quantile"|"standard-deviation"
standardDeviationInterval NumberoptionalWhen
classificationMethod = "standard-deviation", this sets the interval at which each class break should be set (e.g.0.25,0.33,0.5,1).minValue NumberoptionalThe minimum bounding value for the histogram. Use this in conjunction with
maxValueto generate a histogram between custom lower and upper bounds.maxValue NumberoptionalThe maximum bounding value for the histogram. Use this in conjunction with
minValueto generate a histogram between custom lower and upper bounds.numBins NumberoptionalDefault Value: 10Indicates the number of classes to generate for the histogram.
valueExpression StringoptionalAn Arcade expression following the specification defined by the Arcade Visualization Profile. Expressions may reference field values using the
$featureprofile variable and must return a number. This property overrides thefieldproperty and therefore is used instead of an inputfieldvalue. Theviewparameter is required if specifying avalueExpression. When using avalueExpression, client-side statistics are calculated based on the features in the view's extent. To generate statistics for the entire layer, set an equivalentsqlExpression.sqlExpression StringoptionalA SQL expression evaluating to a number. When provided, statistics are queried from the server for the entire layer. Only use this parameter when querying statistics based on an equivalent
valueExpression. This parameter is ignored for client-side layer types.sqlWhere StringoptionalA 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.
optional A SceneView or MapView instance is required when a
valueExpressionis specified.filter FeatureFilteroptionalA feature filter used to filter statistic queries by geometry. This parameter is only used for filtering statistics by geometry. Any attribute filters set on the
FeatureFilter.whereproperty are ignored. Currently, only theintersectsspatial relationship is supported. This is useful if you already define a feature filter by geometry on your layer and want to calculate statistics for the included features. Since version 4.25.optionalDeprecated since version 4.23. UseuseFeaturesInViewinstead.A subset of features for which to generate the histogram.
useFeaturesInView BooleanoptionalOnly applicable when the input
layeris a service-backed FeatureLayer. Whentrue, statistics will be calculated on the client from features visible in the view. Iffalse, statistics will be requested from the service. Since version 4.23.forBinning BooleanoptionalIndicates whether the generated statistics are for a binning or clustering visualization. If
true, then the input field(s) in this method should refer to aggregate fields defined in thefeatureReductionproperty of the layer.signal AbortSignal|null|undefinedoptionalAllows for cancelable requests. If canceled, the promise will be rejected with an error named
AbortError. See also AbortController.ReturnsType Description Promise<HistogramResult> Resolves to a HistogramResult object. Exampleshistogram({ layer: featureLayer, valueExpression: "( ($feature.POP2020 - $feature.POP2010) / $feature.POP2010 ) * 100" view: mapView, numBins: 30 }).then(function(histogramResult){ colorSlider.histogram = histogramResult; });histogram({ layer: featureLayer, field: "Population", normalizationType: "natural-log", sqlWhere: "Population > 0", numBins: 100 }).then(function(histogramResult){ const histogramWidget = Histogram.fromHistogramResult(histogramResult); });