Select to view content in your preferred language

Chart: Grouped lines with date/time as the category? Indoor vs outdoor temp.

1392
6
Jump to solution
10-05-2023 01:00 PM
ArmstKP
Frequent Contributor

I have two separate hosted feature layers.  One with indoor temp and the other with outdoor temp.  I am using an expression to bring them together as a featureset, but it seems I am not able bring in my timestamp field.  No matter what I try it will error.  If I convert the date/time to text, it will work as the category field, but then it will only chart the time using Day as the "Minimum Period" after parsing the dates...it will not chart if I choose "Hour" as the "Minimum Period".

Is it possible to have a date/time as the category field to view hourly line charts of indoor and outdoor temp?  Or do I have to convert the date to something else?

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Try changing the timestamp field to esriFieldTypeDate and in your loop, use Number(l.last_value_update) when you assign the value. That should give you a date field you can use as the category.

- Josh Carlson
Kendall County GIS

View solution in original post

6 Replies
jcarlson
MVP Esteemed Contributor

This seems possible. Can you share you expression, or are the layers private?

Remember, timestamps need to be turned into numbers in your expression.

Number(feature['timestamp_field'])

- Josh Carlson
Kendall County GIS
0 Kudos
ArmstKP
Frequent Contributor

@jcarlson Here is my expression.  last_value_update is my date/time | timestamp field.

 

 

 

var portal = Portal('https://www.arcgis.com')

var sensorHistory = FeatureSetByPortalItem(
    portal,
    'xxx',
    0, // or whatever layer index applies
    ['humidity', text('last_value_update'), 'serial_chart_layer_type'],
    false // unless you really need the geometry, leave it out for performance reasons
)

var outdoorWeatherHistory = FeatureSetByPortalItem(
    portal,
    'xxx',
    0,
    ['humidity', text('last_value_update'), 'serial_chart_layer_type'],
    false
)

var lyrs = [sensorHistory, outdoorWeatherHistory]

var features = []
var feat;

for (var lyr in lyrs){
    for (var l in lyrs[lyr]){
        feat = {
            attributes: {
                humidity: l.humidity,
                last_value_update: Text(l.last_value_update),
                serial_chart_layer_type: l.serial_chart_layer_type,
                
                
                
            }
        }
        
        Push(features, feat)
    }
}

var fs_dict = {
    fields: [
        {name: 'humidity', type: 'esriFieldTypeDouble'},
        {name: 'last_value_update', type: 'esriFieldTypeText'},
        {name: 'serial_chart_layer_type', type: 'esriFieldTypeString'},
        
        
        
    ],
    geometryType: '',
    features: features
}

return FeatureSet(Text(fs_dict))

 

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

Try changing the timestamp field to esriFieldTypeDate and in your loop, use Number(l.last_value_update) when you assign the value. That should give you a date field you can use as the category.

- Josh Carlson
Kendall County GIS
ArmstKP
Frequent Contributor

@jcarlson EXCELLENT!  Very much appreciated!

0 Kudos
ArmstKP
Frequent Contributor

@jcarlson Josh, I have a follow-up question.  If I have a list and have a filter action based on a unique id for that feature to filter the grouped line chart, as of right now it would only draw one of the lines because the other line doesn't have unique id's.  How would I go about or what would be the best approach to have both lines in this scenario?  Basically, I want to always bring in the outdoor temp line, while also bring in the indoor temp line of the feature selected in the list...

0 Kudos
jcarlson
MVP Esteemed Contributor

The only way to really do this is to rework the data in the expression to bring the ID into the other line as well, which doesn't sound simple.

Is there some kind of shared attribute you wanted to filter both lines by?

- Josh Carlson
Kendall County GIS
0 Kudos