Data Expressions for Serial Chart

374
1
04-26-2022 12:43 PM
Labels (3)
EfeUngun
New Contributor

I am trying to create an arcade expression to power a serial chart to show days of the week statistic of incidents in city. I used the weekday function to calculate days of the week which returns number from 0 to 6 and also extracted weekday as a string and then loop through the feature set and copy over the extracted values to a dictionary. The written code below has worked accordingly and the result is the table below. The problem is all the values are shifted. I think it's happening because the day of the week start with Sunday. How can I shift the values or change the start of the week from Sunday to Monday so that Monday there is 1400 accidents, Tuesday 1200, Wednesday, 1580 etc.??

dow_numdowincidents
0Sunday1400
1Monday1200
2Tuesday1580
3Wednesday1500
4Thursday1600
5Friday1111
6Saturday

1020

 

var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'),
'idofthelayer',
0,
['Dates', 'NumberofIncident'], false
);
var sql = "Dates BETWEEN '01/01/2020' AND '12/31/2020'"
var fs_filt = Filter(fs, sql)

var dowDict = {
'fields':[{
'name': 'dow_num',
'type': 'esriFieldTypeInteger'
},{
'name': 'dow',
'type': 'esriFieldTypeString'
},{
'name': 'incidents',
'type': 'esriFieldTypeInteger'
}],
'geometryType': '',
'features': []
};

var index = 0;

for (var feature in fs_filt) {
dowDict.features[index] = {
'attributes':{
'dow_num':Weekday(feature["Dates"]),
'dow':Text(feature["Dates"],'dddd'),
'collisions': feature["NumberofIncident"]
}
}
index++;
}

var fs_dict = FeatureSet(Text(dowDict))
return GroupBy(fs_dict, ['dow_num','dow'],
[{name: 'incidents_by_Date',
expression: 'incidents', statistic: 'COUNT' } ])

 

 

 

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

According to the docs, 0 is definitely Sunday. What does the data table look like? Could it be possible that your data is stored as YYYY-MM-DD 00:00, and that a time zone offset is shifting it to the day prior? Try doing something like

dow_num: Weekday(DateAdd(feature['Dates'], 12, 'hours')),

 on line 29 of the code sample you posted, to see if that fixes it.

Also, don't you want to use the statistic SUM? COUNT is only going to return the number of rows.

- Josh Carlson
Kendall County GIS
0 Kudos