Hi,
Is it possible to show how many records fall within each range on a serial chart?
I've attached a spreadsheet to show what I mean.
Any help much appreciated.
Rachel
Solved! Go to Solution.
What you're describing is a histogram, which is sort of a different animal from the serial chart. It's something others have expressed an interest in as well.
Fortunately, with the latest updates to Dashboards, you can use a Data Expression to create what you need. Try something like this:
var fs = [2,12,24,36,48,55,6,16,26,36,46,12,7,18,12,41]
// static list is for testing; use FeatureSetByPortalItem to get the actual values
var bins = {
'0 to 10': {'attributes': {'bin':'0 to 10', 'count': 0}},
'11 to 20': {'attributes': {'bin':'11 to 20', 'count': 0}},
'21 to 30': {'attributes': {'bin':'21 to 30', 'count': 0}},
'31 to 40': {'attributes': {'bin':'31 to 40', 'count': 0}},
'41 to 50': {'attributes': {'bin':'41 to 50', 'count': 0}},
'51 to 60': {'attributes': {'bin':'51 to 60', 'count': 0}}
}
for(var f in fs){
if(fs[f] < 11){
bins['0 to 10']['attributes']['count'] ++
} else if(fs[f] < 21){
bins['11 to 20']['attributes']['count'] ++
} else if(fs[f] < 31){
bins['21 to 30']['attributes']['count'] ++
} else if(fs[f] < 41){
bins['31 to 40']['attributes']['count'] ++
} else if(fs[f] < 51){
bins['41 to 50']['attributes']['count'] ++
} else{
bins['51 to 60']['attributes']['count'] ++
}
}
var feat_arr = []
for(var b in bins){
Push(feat_arr, bins[b])
}
var out_fs = {
'fields': [{'name':'bin', 'type':'esriFieldTypeString'},
{'name':'count', 'type':'esriFieldTypeInteger'}],
'geometryType': '',
'features': feat_arr
}
return FeatureSet(Text(out_fs))
This results in the following:
As you can see, Data Expressions can be very handy, if built properly. Best of luck!
What you're describing is a histogram, which is sort of a different animal from the serial chart. It's something others have expressed an interest in as well.
Fortunately, with the latest updates to Dashboards, you can use a Data Expression to create what you need. Try something like this:
var fs = [2,12,24,36,48,55,6,16,26,36,46,12,7,18,12,41]
// static list is for testing; use FeatureSetByPortalItem to get the actual values
var bins = {
'0 to 10': {'attributes': {'bin':'0 to 10', 'count': 0}},
'11 to 20': {'attributes': {'bin':'11 to 20', 'count': 0}},
'21 to 30': {'attributes': {'bin':'21 to 30', 'count': 0}},
'31 to 40': {'attributes': {'bin':'31 to 40', 'count': 0}},
'41 to 50': {'attributes': {'bin':'41 to 50', 'count': 0}},
'51 to 60': {'attributes': {'bin':'51 to 60', 'count': 0}}
}
for(var f in fs){
if(fs[f] < 11){
bins['0 to 10']['attributes']['count'] ++
} else if(fs[f] < 21){
bins['11 to 20']['attributes']['count'] ++
} else if(fs[f] < 31){
bins['21 to 30']['attributes']['count'] ++
} else if(fs[f] < 41){
bins['31 to 40']['attributes']['count'] ++
} else if(fs[f] < 51){
bins['41 to 50']['attributes']['count'] ++
} else{
bins['51 to 60']['attributes']['count'] ++
}
}
var feat_arr = []
for(var b in bins){
Push(feat_arr, bins[b])
}
var out_fs = {
'fields': [{'name':'bin', 'type':'esriFieldTypeString'},
{'name':'count', 'type':'esriFieldTypeInteger'}],
'geometryType': '',
'features': feat_arr
}
return FeatureSet(Text(out_fs))
This results in the following:
As you can see, Data Expressions can be very handy, if built properly. Best of luck!
Hello!
Thank you so much for providing this detailed solution but I am having a bit of trouble using the FeatureSetByPortalItem function to get the actual values from my data layer to work. If it's alright, could you perhaps provide a few lines of code that demonstrate how to use the FeatureSetByPortalItem to retrieve field values from an existing feature layer to use in this histogram workflow?
You see, while I know how to properly define the FeatureSetByPortalItem function with the specifics of my data layer's portal, item id, layer id, and field I want to pull from, I just don't understand how I am supposed to implement it into the histogram code. My apologies if this seems like a silly question but as someone who is just barely starting to learn Arcade, anything helps!
I forgot, using a for loop with a FeatureSet is a little different from an array. Let's assume that fs in your case is a FeatureSet.. In that case, use the same code as before, but replace the big for loop with this:
for(var f in fs){
if(f['some-attribute'] < 11){
bins['0 to 10']['attributes']['count'] ++
} else if(f['some-attribute'] < 21){
bins['11 to 20']['attributes']['count'] ++
} else if(f['some-attribute'] < 31){
bins['21 to 30']['attributes']['count'] ++
} else if(f['some-attribute'] < 41){
bins['31 to 40']['attributes']['count'] ++
} else if(f['some-attribute'] < 51){
bins['41 to 50']['attributes']['count'] ++
} else{
bins['51 to 60']['attributes']['count'] ++
}
}
Where 'some-attribute' is the field name.
Also I just noticed I had my bins and conditions in opposing orders... I'll edit the original post.
Josh thanks for your help.
Is this only available in 10.9 version of Enterprise?
Thanks
Rachel
It's not even in Enterprise yet, this is only for the latest Dashboards version, which is AGOL-only at the moment. I'm hoping it's coming in 10.9.1, though!
If you're stuck w/ Enterprise, the next best option is to create a field called "bin" and use a field calculation to populate its value.
Hi Josh,
Yes I'm using Enterprise, I'll have a look at using a field calculation for it.
May thanks
Rachel