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 / Conditional Coloring f...
Power Apps
Answered

Conditional Coloring for PieChart

(0) ShareShare
ReportReport
Posted on by 125

Hi,

 

Is it possible to color code a PieChart in powerapps based on the values? The values are changing in the collection based on what item I am running it on and I was wondering if I could set the colors to these values instead of just assigning the colors in the order the values appear.

 

These are the values and the colors I want:

Covered = Green

Not Covered = Red

Preferred = LightGreen

Unknown = Gray

 

Any suggestions are welcome!

Thank you!

Categories:
I have the same question (0)
  • Leo09 Profile Picture
    212 on at

    I do not see this is possible from below documentation:

    https://powerapps.microsoft.com/en-us/tutorials/control-pie-chart/

  • JRaasumaa Profile Picture
    1,325 on at

    @PAB wrote:

    Hi,

     

    Is it possible to color code a PieChart in powerapps based on the values? The values are changing in the collection based on what item I am running it on and I was wondering if I could set the colors to these values instead of just assigning the colors in the order the values appear.

     

    These are the values and the colors I want:

    Covered = Green

    Not Covered = Red

    Preferred = LightGreen

    Unknown = Gray

     

    Any suggestions are welcome!

    Thank you!


     

    I just tested this in the color values of the chart and it works putting in a conditional statement to decide colors.

     

    In my case I have a collection called "PurchasingData" and a status of completed, putting this code into the color of that pie chart works.

     

    If(LookUp(PurchasingData,Status="Completed",Sum)>10,Magenta,Orange)

     

    So to anwer your question yes, you could have it look to a value and change colors, edit: this might not work if the values are always changing in the pie chart but with some testing I think you could handle all of the values and decide colors.

  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    Yes, you can use the ItemColorSet property of the chart with an expression that defines the colors based on the items of the chart.

     

    For your example, if the items is defined as a collection called 'datasource', and the name of the column based on which you want the color selection is called 'Name', you can use the following expression, using the ForAll and the Switch function, to define the colors:

    ForAll(
     datasource,
     Switch(
     Name,
     "Covered", Color.Green,
     "Not Covered", Color.Red,
     "Preferred", Color.LightGreen,
     Color.Gray))
  • kbirstein1 Profile Picture
    130 on at

    Actually, rather than useing the "ForAll()" function, if you want to assign a specific color to a specific value in a column, then you can just provide the colors the order they appear in the collection. For instance I have a collection called "pieTasks" with the data shown below. I set "Items" of the Pie chart itself (not the "Composite Pie Chart") to "pieTasks" and the "ItemColorSet" to [Color.Yellow,Color.GreenYellow,Color.Red,Color.Blue,Color.DarkBlue] and that gives me Yellow for the first "Time Scope", which is 'Due Today", GreenYellow for the second "Time Scope", which is "New Today", Red for third "Time Scope" which is "Overdue', etc.

    pieTasks.png

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    The resulting Pie Chart gives me the colors I want:

     

    pieChart.png

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    You'll find simply providing colours in order breaks down if you have a chart element of zero value, as the next element will have the colour value you assigned to this element.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @CarlosFigueira wrote:

    Yes, you can use the ItemColorSet property of the chart with an expression that defines the colors based on the items of the chart.

     

    For your example, if the items is defined as a collection called 'datasource', and the name of the column based on which you want the color selection is called 'Name', you can use the following expression, using the ForAll and the Switch function, to define the colors:

    ForAll(
     datasource,
     Switch(
     Name,
     "Covered", Color.Green,
     "Not Covered", Color.Red,
     "Preferred", Color.LightGreen,
     Color.Gray))

    @CarlosFigueira Hello! This solution almost worked for me, what if i want the condition to be bigger than a number? Like if is bigger than 100, than Green, if is lower Red, and if is equal Yellow., for example.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Anonymous wrote:

    @CarlosFigueira wrote:

    Yes, you can use the ItemColorSet property of the chart with an expression that defines the colors based on the items of the chart.

     

    For your example, if the items is defined as a collection called 'datasource', and the name of the column based on which you want the color selection is called 'Name', you can use the following expression, using the ForAll and the Switch function, to define the colors:

    ForAll(
     datasource,
     Switch(
     Name,
     "Covered", Color.Green,
     "Not Covered", Color.Red,
     "Preferred", Color.LightGreen,
     Color.Gray))

    @CarlosFigueira Hello! This solution almost worked for me, what if i want the condition to be bigger than a number? Like if is bigger than 100, than Green, if is lower Red, and if is equal Yellow., for example.


    Nevermind, i made it work, instead of "Switch", i used an "If" function: ForAll(datasource;If(Name>100;Color.Green;Name<100;Color.Red;Name=100;Color.Yellow))

  • gretchunkim Profile Picture
    138 on at

    Best gold answer here! 

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I am using the same formula. However, the same status items are creating more and more slices. I need to get the chart with 3 slices. 1 for Approved, 1 for Pending, 1 for Rejected (basically distinct slices). In this image all 3 pending statuses should be together with one big slice instead of 3 separate ones. If I add one more Approved item, it should show all approved items together within same slice. Can someone help?

     

    Distinct(Expenses,Switch('Expense Status','Expense Status (Expenses)'.Approved,Green,'Expense Status (Expenses)'.Pending,Orange,'Expense Status (Expenses)'.Rejected,Red))

     

    HarshaVardhanR_0-1670664481234.png

     

  • ITSYS Profile Picture
    28 on at

    Hello everyone,

    I'm  building an application request for user. I used pie chart to show report but color set not true.  I try to code  to set color :

    ForAll('Report System',Switch(Status.Value ,"Resolved",Color.Green,"Pending",Color.Orange))
    Could you pls help to set color for this case.

     

    ITSYS_0-1682580854742.png

     

     

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 477

#2
WarrenBelz Profile Picture

WarrenBelz 341 Most Valuable Professional

#3
11manish Profile Picture

11manish 317

Last 30 days Overall leaderboard