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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
vijaybansal3000
Frequent Visitor

line chart - color gradient

I am trying to look at variation of ridership values with month. I have plotted data for 10 years but all the lines appear in different colors which makes it little difficult to understand unless you have legend opened on the side

Is there any way by which I can change the color of my years based on a gradient. For example all the lines are shades of green; 2006 being dark shade of green, 2000 being lighter shade of green and 1996 being the lightest.

Capture.PNG

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

You could do it in R, though you lose interactivity back into your dataset etc.  Something like:

 

library(ggplot2)    # Needed for ggplot
# Avoid having to reference dataset$ each time in function calls
attach(dataset)

#Plot the Count dataset by Month and Year, with Year to set the fill colour
ggplot(dataset, aes(x=Month, y=Count, group=Year, colour=Year)) +
#Use lines on the plot
  geom_line() +
Restrict the colur hue to (around) the green range
  scale_color_hue(h=c(90,180))

 You may need to fiddle with the scale_colour_hue parameters to get exactly what you want.

View solution in original post

5 REPLIES 5
mihart
Employee
Employee

Hi @vijaybansal3000,

You could select the paint roller icon and expand "Data colors" and manually assign different gradients of 1 or more colors. It's not the ideal way, but it will accomplish what you want. green.png

Thanks @mihart.  I am looking for some way like below which can be acheived in Tableau. 

Capture_tableau.PNG

Anonymous
Not applicable

You could do it in R, though you lose interactivity back into your dataset etc.  Something like:

 

library(ggplot2)    # Needed for ggplot
# Avoid having to reference dataset$ each time in function calls
attach(dataset)

#Plot the Count dataset by Month and Year, with Year to set the fill colour
ggplot(dataset, aes(x=Month, y=Count, group=Year, colour=Year)) +
#Use lines on the plot
  geom_line() +
Restrict the colur hue to (around) the green range
  scale_color_hue(h=c(90,180))

 You may need to fiddle with the scale_colour_hue parameters to get exactly what you want.

Thanks @Anonymous. This seems to be a good way. Though I would have loved this as a feature inbuilt in PowerBI itself without going to R code.

Hi @vijaybansal3000,

Currently, it is impossible to change the color of years based on a gradient in Power BI Desktop, an idea about this issue has been submitted in the following link, please vote for it. In your scenario, you can set discrete set of colors using Format option as mihart’s post.  Or set color using R code following Steve’s suggestion.

https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/15906193-continuous-color-palette...


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.