cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
StuPower
Helper I
Helper I

Strange behaviour with ItemColorSet on a barchart

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User
Super User

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

Brilliant thankyou for such a detailed reply!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (2,030)