adding two indications in the same serial/bar chart

652
7
Jump to solution
02-28-2022 01:49 AM
Labels (1)
HalaAbdelmaksoud
Occasional Contributor

Hi all,

I have a question about how to add two indications on the same serial chart: I want to combine the solved and the total number of features at the same chart.

two line charts.png

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Well, you can use a Data Expression to do this, too. Basically, you'd pull in the reports layer and throw them all into a "total" category, and then take the solved ones and add them again. This should enable you to visualize the chart the way you'd like.

 

var portal = Portal('your portal url')

// Get reports featureset
var fs = FeatureSetByPortalItem(
    portal,
    'itemid of your service',
    0, // or whatever layer index the specific layer is at
    ['status', 'report_date'],
    false
)

// Output dictionary
var out_dict = {
    fields: [
        {name: 'type', type: 'esriFieldTypeString'},
        {name: 'report_date', type: 'esriFieldTypeDate'}
    ],
    geometryType: '',
    features: []
}

// Iterate over features
for (var f in fs){
    // Add feature to output dict as a "total" type
    Push(
        out_dict['features'],
        {
            attributes: {
                type: 'Total',
                report_date: Number(f['report_date']) // You need to cast the date as a number to be correctly interpreted
            }
        }
    )
    
    // If report is a "solved" type, add it again
    If (f['status'] == 'solved'){
        Push(
            out_dict['features'],
            {
                attributes: {
                    type: 'Solved',
                    report_date: Number(f['report_date']) // You need to cast the date as a number to be correctly interpreted
                }
            }
        )
    }
}

// Convert dict to FeatureSet
return FeatureSet(Text(out_dict))

 

 

I used this expression with a sample FeatureSet that had the following records:

StatusDate
solvedToday
solvedToday
receivedToday
processingToday
solvedYesterday
receivedYesterday
receivedYesterday

 

Since "solved" records are added twice, the output FeatureSet had 10 records in it, and I was able to make this chart:

jcarlson_0-1646067695201.png

 

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
7 Replies
jcarlson
MVP Esteemed Contributor

How is the data organized? There's no reason you shouldn't be able to do this, but it depends on where the data's coming from and what it looks like. Is "solved" a field?

- Josh Carlson
Kendall County GIS
0 Kudos
HalaAbdelmaksoud
Occasional Contributor

I have a layer for reports, and it has a field called "status" which contains values(received, processing, and solved).

I want to make a serial chart,  per day, for the solved features on a line and the total of all features(received, processing, and solved) on another line.

So I used a chart for grouped values by category "date", then split by the field "status", but this way did not give me the desired output.

 
 
 
 
 
0 Kudos
jcarlson
MVP Esteemed Contributor

Well, you can use a Data Expression to do this, too. Basically, you'd pull in the reports layer and throw them all into a "total" category, and then take the solved ones and add them again. This should enable you to visualize the chart the way you'd like.

 

var portal = Portal('your portal url')

// Get reports featureset
var fs = FeatureSetByPortalItem(
    portal,
    'itemid of your service',
    0, // or whatever layer index the specific layer is at
    ['status', 'report_date'],
    false
)

// Output dictionary
var out_dict = {
    fields: [
        {name: 'type', type: 'esriFieldTypeString'},
        {name: 'report_date', type: 'esriFieldTypeDate'}
    ],
    geometryType: '',
    features: []
}

// Iterate over features
for (var f in fs){
    // Add feature to output dict as a "total" type
    Push(
        out_dict['features'],
        {
            attributes: {
                type: 'Total',
                report_date: Number(f['report_date']) // You need to cast the date as a number to be correctly interpreted
            }
        }
    )
    
    // If report is a "solved" type, add it again
    If (f['status'] == 'solved'){
        Push(
            out_dict['features'],
            {
                attributes: {
                    type: 'Solved',
                    report_date: Number(f['report_date']) // You need to cast the date as a number to be correctly interpreted
                }
            }
        )
    }
}

// Convert dict to FeatureSet
return FeatureSet(Text(out_dict))

 

 

I used this expression with a sample FeatureSet that had the following records:

StatusDate
solvedToday
solvedToday
receivedToday
processingToday
solvedYesterday
receivedYesterday
receivedYesterday

 

Since "solved" records are added twice, the output FeatureSet had 10 records in it, and I was able to make this chart:

jcarlson_0-1646067695201.png

 

 

- Josh Carlson
Kendall County GIS
0 Kudos
HalaAbdelmaksoud
Occasional Contributor

Thank you so much

0 Kudos
HalaAbdelmaksoud
Occasional Contributor

@jcarlson it works, but after I click done, it gives me "no data" on the dashboard

Untitled5.png

0 Kudos
jcarlson
MVP Esteemed Contributor

You mean it shows you the data when you're configuring the chart? Or it only shows it in the Expression Builder?

- Josh Carlson
Kendall County GIS
0 Kudos
HalaAbdelmaksoud
Occasional Contributor

it shows the data on the chart only while configuring the chart

0 Kudos