How To Show Total Count.

675
5
05-14-2019 10:42 PM
irtizahussain
Occasional Contributor

Hello. i'm using arcgis api 4.10 where i want to show the total num of count, let's suppose i have a Map Server service (http://...:.../...//MapServer/13) of customers so i want to show the total number of customers by using service and relevant field like (Number_of_SUM) of this service, how can i do this!!

Tags (1)
0 Kudos
5 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Irtiza,

   Have you looked into StatisticDefintion? This class is for exactly what you are wanting to do.

irtizahussain
Occasional Contributor

Thanks Robert,

Can you show some working examples of this!! as it is difficult to understand for me.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Irtiza,

   Here is a snipit of code for that:

var statisticDefinition2 = new StatisticDefinition({
  statisticType: "count",
  onStatisticField: "Muni",
  outStatisticFieldName: "muniCount"
});
query.where = "1=1";
query.outStatistics = [statisticDefinition2];
query.groupByFieldsForStatistics = ["Muni"];
query.outFields = ["Muni"];

featureLayer.queryFeatures(query).then(function(results){
...
  var count = feat.attributes.muniCount;
...
});
0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

What Robert suggested. You can also use queryFeatureCount on FeatureLayer or FeatureLayerView if you have created a FeatureLayer.

Use FeatureLayerView.queryFeatureCount, if you want to get the total count of features available on the client (fast and performant).

User FeatureLayer.queryFeatureCount, if you want to get the exact number of features that meet your requirements. This will issue a network request to the server.

irtizahussain
Occasional Contributor

Thanks Undral,

Can you show some working samples of this!! as it is difficult to understand for me.

0 Kudos