This sample demonstrates how to use AttributeBinsQuery API to calculate the total number of hurricanes per year between 1925 and 2024 in the PST time zone. It leverages a date binning with a yearly interval to group the data. The result of attribute binning is displayed in an interactive histogram and ArcGIS Bar Chart, allowing users to explore trends and patterns in the hurricanes data.

Data binning is a technique that groups data into bins or categories based on specific intervals or ranges, making it easier to analyze trends, visualize patterns, and simplify the interpretation of large datasets.

How it works

When the application starts, the total number of hurricanes per year between 1925 and 2024 is calculated by calling queryAttributeBins() method on the hurricane tracks feature layer. The results of this query are then displayed as a histogram in the calcite-slider.

// get total hurricanes by year between 1925 and 2024 in the PST time zone
// using a date bin query with a yearly interval
const hurricanesQuery = new AttributeBinsQuery({
binParameters: new DateBinParameters({
field: "Hurricane_Date",
start: new Date(1925, 0, 1),
end: new Date(2024, 11, 31),
interval: {
value: 1,
unit: "years",
},
}),
outTimeZone: "America/Los_Angeles",
cacheHint: true,
});
// query the layer for the total hurricanes by year
const hurricanesQueryResult = await layer.queryAttributeBins(hurricanesQuery);
const histogramData = hurricanesQueryResult.features.map((feature) => {
const year = new Date(feature.attributes.lowerBoundary).getFullYear();
const count = feature.attributes.frequency;
return [year, count];
});
// get the histogram element and set the histogram data
const hurricanesHistogram = document.getElementById("hurricanes-histogram");
hurricanesHistogram.histogram = histogramData;
hurricanesHistogram.histogramStops = [
{
offset: 0,
color: "#52aeb7",
},
];

The code snippet shows how to create a bar chart with charts model that displays the total number of hurricanes by month. With syncViewSelection and syncViewTimeExtent set to true, the bar chart is synchronized with the map view for both selection and time extent changes.

// initialize the bar chart by creating a bar chart model and set the x-axis field
// to month to show the total hurricanes by month for the selected years
const barChartModel = await createModel({ layer: layer, chartType: "barChart" });
barChartModel.xAxisField = "month";
barChartModel.titleSymbol = {
type: "esriTS",
font: {
family: "Avenir Next",
size: 15,
weight: "bold",
},
};
barChartModel.titleText = "Total hurricanes by month 1925 - 1935";
barChartElement.hideLoaderAnimation = true;
barChartElement.layer = layer;
barChartElement.view = viewElement;
barChartElement.model = barChartModel;
// enable syncing of the bar chart with the map view for both selection and time extent changes
barChartElement.syncViewSelection = true;
barChartElement.syncViewTimeExtent = true;

Users can filter the hurricane tracks by adjusting the slider thumbs to display the hurricane tracks for the selected years. The total hurricanes by month bar chart is updated to show the total number of hurricanes between the selected years.

2DFeatureLayerqueryAttributeBinsAttributeBinsQueryDateBinParameterschart-componentsarcgisSelectionCompletebarChartviewOnReadyarcgis-chartarcgis-expandarcgis-legendarcgis-maparcgis-zoommap-componentscalcite-blockcalcite-panelcalcite-shellcalcite-slidercalcite-components