16 Replies Latest reply: May 20, 2016 1:26 AM by Pranjal Gharat

# How to define Chart colours

Dear community,

another rahter basic question for you,

I am trying to analyse the colours of the Bikes i sel in a Pie Chart,

The values in the "colour" field are of course: 'black','pink','white etc....

Now when i have a chart of COURSE i want the chart segments to have exactly that colour and not blue for 'black'

I guess this is really easy but i have no idea how to do this

Seb

• ###### Re: How to define Chart colours

Hi

You could apply the colours like this. Click the + next to the expression in the Expression tab. Then enter the following colour expression:

=pick(match(Colour, 'black', 'white', 'pink', ...etc), RGB(0,0,0), White(), RGB(128, 0, 0), ...etc)

Hope that helps

Jonathan

• ###### Re: How to define Chart colours

hmm i have inputted the expression based on your recommendation in the expression ("sum(sales)") clicked on the + and entered the following in the "pie popout":

=pick(match(Colour, 'black'), RGB(0,0,0))

But the black is still blue

What am i doing wrong?

• ###### Re: How to define Chart colours

scdrawert wrote:

hmm i have inputted the expression based on your recommendation in the expression ("sum(sales)") clicked on the + and entered the following in the "pie popout":

=pick(match(Colour, 'black'), RGB(0,0,0))

But the black is still blue

What am i doing wrong?

This expression assumes that the colour field is named Colour and is the dimension of the pie chart (so that each slice only has one possible colour). Update the expression with the correct field name.

Jonathan

• ###### Re: How to define Chart colours

correct - the color value is stored in the field named "colour" possible value is e.g. "black"

i have now a massive IF(colour='black".... chain in there . its not very elegant but it works for now :/

• ###### Re: How to define Chart colours

Remember that field names are case sensitive, so field Colour is differenr to field colour. Try the correct one in the pick(match() statement. Much easier to write and maintain than nested ifs!

• ###### Re: How to define Chart colours

Hi Jonathan,

wouldn't this also work somehow in the pie chart option of the Expresssion?

if(colour='red',RGB(255,0,0))

• ###### Re: How to define Chart colours

Hi,

Go to properties of the chart object and go to colors tab.

For Eg:

if you are using pie chart and it having 6 different value in one dimension.

Jan,Feb,March,April,May and June.

If you want to change the color , you have to change the (Colors 1-6) in Data Appearance in "Color tab". Just click the color which you don't want and change the color and click apply.

Selva

• ###### Re: How to define Chart colours

hmm sorry but this was not the solution - or i did not understand well what you wanted to tell me,

:-/

• ###### Re: How to define Chart colours

HI

Pie Chart in first sheet..

Please see the background color expression in expression tab. by expand the '+' sign.

Hope that helps

• ###### Re: How to define Chart colours

damn - cannot "recover" the file - i am still on personal edition.

Can you paste the expression here?

• ###### Re: How to define Chart colours

You can change the colours in the properties of the graphic, 'Colour' sheet, so I think you need to have all the colurs in the chart, put them in the same order of your colours in the properties and select de checkbox Persistent colours

Tell me if this works.

Regards

• ###### Re: How to define Chart colours

hmm no - i just did this once but as soon a i change the parameters (i.e. selct a differnett country) then the colours are messed up again . i guess i need to code this somehow like Jonathan suggested but cannot get it to work.

• ###### Re: How to define Chart colours

I suggest building a table for the colors instead of handling it in expressions.  You're surely going to want these colors in multiple places, which means repeating the expression.  You could create a variable to hold the expression and use the variable, but I'd build a color table instead.  I just think it's cleaner, and would allow you to load colors from an external source like a spreadsheet if desired.  It requires script access and a reload to change, of course, which might occasionally be an issue.

The attached example allows you to explicitly assign colors to customers by RGB values, and then automatically builds random colors for any customers you didn't assign.  You don't want the random color part in this case, so skip that and make certain that all colors are assigned.

The color expressions in these charts are also more complicated than you'd likely need.  All you'd need is rgb(R,G,B) in most cases.  These charts were doing more complicated things like highlighting the weekday data.

Edit: Ooops, sorry, I see you're in personal edition.  I'll make another edit to tell you all the relevant information.

Edit 2: Actually, rather than describe the example I posted, let me just give you what I think you should do.  Consider a spreadsheet instead of an inline load, but here's the idea.  In the script:

[Colours]:
colour,R,G,B
Red,255,0,0
Pink,255,150,150
Green,0,255,0
etc.
];

Then in the chart, in the background colour expression:

rgb(R,G,B)

• ###### Re: How to define Chart colours

Hi John,

This is great!!.

We have similar scenario where we are applying colors to charts using ColorTable.

We have two tables in QV

Data table with all facts and dimensions

ColorT table with mapping dimension and RGB values

ColorT table doesn't have all the values from my dimension column hence it will apply colors to values which are present in ColorT table.

After applying formula in background color:

=RGB(R,G,B)

We need to change the color for other values to default colors.

• ###### Re: How to define Chart colours

Maybe something like if(R+G+B,rgb(R,G,B)). As long as you assign null to the color, it should use the defaults.

However, if you look closely at the example, I gave an arguably more robust solution to the same problem, which was to assign random colors to values that you haven't assigned explicit colors to. That way you're still using the same colors for those values across charts, even when you don't know what the values will be ahead of time to explicitly assign colors to them. On the down side, random colors won't always look very good, but if you reload the example over and over, I think the way I assigned random colors produces pretty good results for customers D & E.

• ###### Re: How to define Chart colours

Thanks John!!

It worked !!!