cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PAB
Advocate III
Advocate III

Conditional Coloring for PieChart

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!

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

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))

View solution in original post

8 REPLIES 8
Leo09
Helper V
Helper V

I do not see this is possible from below documentation:

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

JRaasumaa
Memorable Member
Memorable Member


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

CarlosFigueira
Power Apps
Power Apps

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))

View solution in original post

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

Anonymous
Not applicable

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.


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


@PedroViviani 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))

Best gold answer here! 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (57,171)