web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Strange behaviour with...
Power Apps
Answered

Strange behaviour with ItemColorSet on a barchart

(0) ShareShare
ReportReport
Posted on by 57

Hello

 

A user is having some strange behaviour when trying to change a bar charts column colours.

 

They have a SharePoint list with a single line of text column called "Status"

 

SharePoint records are loaded into a collection (Ive also tried pointing the chart directly to the SharePoint list) -

ClearCollect(Records,
 'SharePoint List'
);

The bar chart 'Items' is set to -

AddColumns(
 GroupBy(
 Records,
 "Status",
 "SubGrp"
 ),
 "Count",
 CountRows(SubGrp)
)

The bar chart ItemColorSet is set to -

ForAll(
 Records,
 Switch(
 Status,
 "complete",
 Color.Blue,
 "on track",
 Color.Green,
 "delayed",
 Color.Red,
 "Paused",
 Color.Purple,
 Color.Black
 )
)

But all the columns show as the colour blue, matching the "complete" records color. If i remove "complete" from the formula -

ForAll(
 Records,
 Switch(
 Status,
 "on track",
 Color.Green,
 "delayed",
 Color.Red,
 "Paused",
 Color.Purple,
 Color.Black
 )
)

All the columns are then black.

 

If i exclude any records that equal "complete" when populating the collection -

ClearCollect(
 List,
 Filter(
 'SharePoint List',
 Status <> "complete"
 )
);

Then all the remaining columns are coloured correctly as per the switch formula.

 

The only difference is theres 26 records that equal "complete" and only 1 of the other types but can't see why that would make a difference.

 

Any ideas?

 

Thanks

 

Categories:
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @StuPower 

    The order of the color records in the ItemColorSet must match and be in the same order and same number of records as the Items of the chart.

     

    This can also be done without a collection.

    Do the following steps:

    1) Add a new SCROLABLE screen to your app.  On that screen, select the Canvas control that is created on it.  Resize to be very small and then ctrl-X (cut) it from the screen.

    2) Delete the new screen you just added.

    3) Back on your other screen, paste the canvas you just cut from the other new screen.

    NOTE: you are creating what I call a dynamic variable.  You can keep it on a separate screen, but I like to have these in context of where they are used.

     

    Now, I will assume that the canvas is Canvas1 and the DataCard in it is DataCard1 if not substitute as needed.

    1) Go to DataCard1 and then choose the Update property. 

    2) In the Update property, but the following formula:

    {
     ChartItems:
     AddColumns(
     GroupBy('SharePoint List',
     "Status",
     "SubGrp"
     ),
     "Count", CountRows(SubGrp),
     "_color", 
     Switch(Status,
     "complete", Blue,
     "on track", Green,
     "delayed", Red,
     "Paused", Purple,
     Black
     )
     )
    }

     

    Now, in the Items property of your Chart : DataCard1.Update.ChartItems

    And in the ItemColorSet property : ForAll(DataCard1.Update.ChartItems, {Value: _color})

     

    You will now have a dynamic (will change as underlying list values change) chart with the proper colors.

     

    I hope this is helpful for you.

  • StuPower Profile Picture
    57 on at

    Brilliant thankyou for such a detailed reply!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard