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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Brilliant thankyou for such a detailed reply!

Helpful resources

Announcements
PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Top Solution Authors
Top Kudoed Authors
Users online (3,222)