I am creating a Dashboard with several different serial charts. My data has a length field in feet; I am not able to edit the data or add a field. I need to have a bar chart that displays the length in miles. Is there a way for me to calculate this within the serial chart?
Try this:
I made one minor change; I changed the bolded part to "length_Miles" and it returns the converted value in miles. The only issue is it is returning the Path_Rating_txt as all null values. I tried adding a new variable to include the Path_Rating but it is returning all null values as well.
This works when I run it in the data expression builder but when I close it I get "Unable to execute arcade script" when trying to select it to use in my serial layer.
You need to build an array to push the features in, which is var features = []; just after you connect to your portal, and you need to return the converted values (or whatever you will call your fs). See below:
var portal = Portal('https://arcgis.com');
// Provide the actual Portal Item ID and layer indexvar fs = FeatureSetByPortalItem(portal, '<PORTAL_ITEM_ID>', 2, ['PATH_Length', 'Path_Rating_txt'], false);
// Initialize the output arrayvar features = [];
for (var f in fs) {var lengthMiles = Round(f['PATH_Length'] / 5280, 2);var pathRating = f['Path_Rating_txt'];
Push(features, {attributes: {lengthMiles: lengthMiles,Path_Rating_txt: pathRating}});}
var convertedValues= {fields: [{ name: 'Path_Rating_txt', type: 'esriFieldTypeString' },{ name: 'lengthMiles', type: 'esriFieldTypeDouble' }],geometryType: '', // Define geometryType if needed (e.g., 'esriGeometryPoint')features: features};
return convertedValues;
I really appreciate your help. I have tried to apply this and keep getting "Test execution error: Invalid variable assignment. Verify test data.
here is what I have put in:
I see what you're getting at. Your need to create a new array and push the converted values into that array:
It is a portal item, I was trying to do a FeatureSetByPortalItem but keep getting the error: Test execution error: ',' expected.. Verify test data.
I need to be able to acce the "Path_Rating" field and the "PATH_Length" field and I need calculate the "PATH_Length" field so that it is divided by 5280 to convert it to miles.
An example of your data - fields etc
I can get one, what do you mean by a snapshot?
The best way to do this, without having to create a new field in the data, would be to use the Dashboard Arcade function to return a new feature layer in the dashboard, where the units are converted from feet to miles.
Do you have a snapshot of your data?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.