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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Assigning "random" col...
Power Apps
Unanswered

Assigning "random" colours to buttons

(0) ShareShare
ReportReport
Posted on by

So here is the situation, I would like to have a gallery listing similar to the following:

madeg_0-1645024813052.png

As one can see each item of the gallery has a button with the first letter (I know how to get that), but have different colours for each.  I was wondering if there was a way to have distinct colours for each of the listings.  The only way i can think of is to have a collection with a list of background colour and text colour set up and somehow mapping that to each of the items. 

 

Would it be possible to generate a random colour or even better generate a colour scheme based on the name so that a company name is always represented by the same colours?  

 

Thanks!

Mark

Categories:
I have the same question (0)
  • PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on at

    @Anonymous As you said, if you want to have always the same color for a company you need to define this somewhere.

    For example, you could use this code in App.OnStart

     

    Set(
     _companyColours,
     {
     company1: {
     fill: RGBA(
     255,
     255,
     255,
     1
     ),
     text: RGBA(
     10,
     10,
     20,
     1
     )
     },
     company2: {
     fill: RGBA(
     255,
     255,
     255,
     1
     ),
     text: RGBA(
     10,
     10,
     20,
     1
     )
     }
     }
    )

     

    So you would define a variable with a property for each company.

     

    In your App you can reference to these bvalues like that..

     

    _companyColours.company1.fill
    
    or 
    
    _companyColours.company1.text

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

  • Community Power Platform Member Profile Picture
    on at

    thanks, yes that is what i had in mind but it wont work as the companies, or event he number of companies is not predefined and comes from an external source.  i needed a way of converting the name (for example) into a HEX value for a colour maybe?

  • PowerRanger Profile Picture
    3,458 Super User 2024 Season 1 on at

    @Anonymous Maybe this approach will solve your needs. In my example I faked a list of customers. So, if you can produce a Table with unique customer names this solution will work.

     

     

     

    ClearCollect(myCustomers,["Customer 1", "Customer 2","Customer 3","Customer 4","Customer 5"])

     

     

     

    In a second step I used this code:

    This code will "iterate" through all customers in myCustomers and returns a record with a Random RGBA value

     

    ClearCollect(
     _customerColorSetting,
     ForAll(
     myCustomers,
     {
     CustomerName: ThisRecord.Value,
     fill: RGBA(
     RandBetween(
     1,
     255
     ),
     RandBetween(
     1,
     255
     ),
     RandBetween(
     1,
     255
     ),
     1
     )
     }
     )
    )

     

     

     

     

    This will produce a Table like this:

    PowerRanger_2-1645443095144.png

     

     

    to apply this to a customer record in a Gallery for example your code would look something like. You could for example place this in the TemplateFill Property of a Gallery:

     

     

     

    LookUp(_customerColorSetting,CustomerName = ThisItem.Value).fill

     

     

    PowerRanger_1-1645443062670.png

    The Items Property of my Gallery is set to "myCustomers"

     

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

     

     

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard