Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
juan_123
Frequent Visitor

Specific colors for different products in a line chart

Hi, I have a line chart with dates on the X-axis, prices on the Y-axis and product names in the legend field.

 

How can I assign a specific color for each product?

1 ACCEPTED SOLUTION
AllisonKennedy
Super User
Super User

@juan_123 

Unfortunately Conditional formatting with line charts isn't possible with the default visual. Best thing to do is ensure your products sort order matches the order of the colours in your Power BI theme, and those are the colours that will be applied to the lines for each product. 

 

I actually just published a blog on something similar: https://excelwithallison.blogspot.com/2023/02/how-power-bi-picks-legend-colours.html 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

6 REPLIES 6
v-jianboli-msft
Community Support
Community Support

Hi @juan_123 ,

 

Although PowerBI does not currently support conditional formatting for legends, you can manually set different colors for them if you do not have a large number of legends.

vjianbolimsft_0-1675908413233.png

vjianbolimsft_1-1675908425134.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

grantsamborn
Solution Sage
Solution Sage

Thanks! I followed all the steps on the link. The thing is that that works fine when you are formatting colors based on the X-axis values. I need to format colors based on the legend field... And there's no option to select a formula for the colors in that case...

AllisonKennedy
Super User
Super User

@juan_123 

Unfortunately Conditional formatting with line charts isn't possible with the default visual. Best thing to do is ensure your products sort order matches the order of the colours in your Power BI theme, and those are the colours that will be applied to the lines for each product. 

 

I actually just published a blog on something similar: https://excelwithallison.blogspot.com/2023/02/how-power-bi-picks-legend-colours.html 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi @AllisonKennedy many thanks for the answer! Hope Power BI adds this functionality. Do you know if there's any custom visual that allows you to set colors from the legend field?

Read your blog, very interesting what you said about the seemingly random colors. Good to know you can set more than just 8 colors in the theme.

Thanks!
Juan

 

@juan_123  You can vote for the idea on PowerBI Ideas https://ideas.powerbi.com/ideas/ and post the link here for more visibility.

 

Sorry I dont' know a custom visual off the top of my head that does this, maybe try posting a new question and link to this thread and ask for custom visual suggestions. I know things like Charticulator and Deneb give you lots of custom capabilities so you may be able to form your own visual, but that's a lot of time and learning required. Let me know if you find a good custom visual that works!


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.