Select to view content in your preferred language

Create serial chart using FeatureSetbyPortalItem Arcade function

564
2
Jump to solution
01-02-2023 09:20 PM
Labels (1)
KhadijaSafi
New Contributor

Using Dashboards I'm trying to create a serial chart that shows total count of features within each layer with the layer name on x-axis and count on y-axis. The individual layers come from the same hosted feature layer which is why the itemId is the same for each layer

// Access organization's ArcGIS Online URL
var portal = Portal("https.blank.maps.arcgis.com");

// Access each layer item as a feature set from the portal
var waterLine = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var sanLine = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var roads = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var waterPoly = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var sanPoly = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var other = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var building = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var bridge = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)
var boardwalk = FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false)

var totalCount = Count(waterLine) + Count(sanLine) + Count(roads) + Count(waterPoly) + 
Count(sanPoly) + Count(other) + Count(building) + Count(bridge) + Count(boardwalk)

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount}}],
};
	
//Return dictionary cast as a feature set
return FeatureSet(Text(Dict));

Any help would be much appreciated, I'm very new to Arcade.

 

0 Kudos
1 Solution

Accepted Solutions
CarmelConnolly
Esri Regular Contributor

I think you're very close!

 

Couple of things to check/try

  • portal is a reserved keyword, change it to another string to remove that as an issue, for example

 

var portalItem = Portal("https://blank.maps.arcgis.com");

 

  • Check your URL is in the correct format, the format in the code isn't ri

 

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}, {name: 'layername', type: 'esriFieldTypeString'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount, layername: "bridge"}}],
};
	​

ght but might just have been from you swapping out your specific URL

 

  • The Dict you're building needs to include layer name element if you want to display the layer name on the chart

 

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}, {name: 'layername', type: 'esriFieldTypeString'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount, layername: "bridge"}}],
};
	

 

The Dict your building is based upon 9 layers, but these are all the same layers. Are 'building', 'bridge' etc sub layers in the 51dc078a4b35479fb975114ca4abf546 item or attributes in the 0 sub layer? If it's the latter, you may want to filter so you're getting counts of the individual categories, instead of the layer as a whole, for example

 

var building = Filter(FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false), "fieldName = 'building'");​

 

 

  • The Dict your building is just returning one feature, and one total count, not the individual counts of each layer. Consider adding more features to your Dict

 

 

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}, {name: 'layername', type: 'esriFieldTypeString'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount, layername: "bridge"}, {total: totalCount, layername: "building"}}],
};

 

 

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

When you attempt to use this code, what kind of response do you get? I don't see any obvious errors in your code.

- Josh Carlson
Kendall County GIS
0 Kudos
CarmelConnolly
Esri Regular Contributor

I think you're very close!

 

Couple of things to check/try

  • portal is a reserved keyword, change it to another string to remove that as an issue, for example

 

var portalItem = Portal("https://blank.maps.arcgis.com");

 

  • Check your URL is in the correct format, the format in the code isn't ri

 

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}, {name: 'layername', type: 'esriFieldTypeString'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount, layername: "bridge"}}],
};
	​

ght but might just have been from you swapping out your specific URL

 

  • The Dict you're building needs to include layer name element if you want to display the layer name on the chart

 

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}, {name: 'layername', type: 'esriFieldTypeString'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount, layername: "bridge"}}],
};
	

 

The Dict your building is based upon 9 layers, but these are all the same layers. Are 'building', 'bridge' etc sub layers in the 51dc078a4b35479fb975114ca4abf546 item or attributes in the 0 sub layer? If it's the latter, you may want to filter so you're getting counts of the individual categories, instead of the layer as a whole, for example

 

var building = Filter(FeatureSetByPortalItem(portal, "51dc078a4b35479fb975114ca4abf546", 0, ["*"], false), "fieldName = 'building'");​

 

 

  • The Dict your building is just returning one feature, and one total count, not the individual counts of each layer. Consider adding more features to your Dict

 

 

var Dict = {
	fields: [{name: 'total', type: 'esriFieldTypeInteger'}, {name: 'layername', type: 'esriFieldTypeString'}], 
	geometryType: '',
	features: [{attributes: {total: totalCount, layername: "bridge"}, {total: totalCount, layername: "building"}}],
};