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

Color a line chart based on measure name

Hi,

I have a line chart with several measures which are, say, labeled by

'Forecast 1'
'Forecast 2'
'Forecast 3'

saz_0-1678955426880.png

 

I would like to specify a color for each of the corresponding lines in the chart. I was trying to use "color by expression" but I can't think of a way to reference to the name of the measures. I found a related question on bar charts but the approach doesn't seem to work for line charts.

Thank you!

 

Labels (2)
3 Replies
N30fyte
Creator

Change your measures to master measures (if you haven't already).

In the Edit measure dialog, for each measure specify the colour you want for its line under Measure color. Save.

In the Chart Properties box, open Appearance - Colors and Legend, use Single Color and set Use library colors to Measure.

saz
Contributor II
Author

Thank you for the suggestion! This would certainly work, but if possible I would rather avoid adding a master measure for each of the measures. The reason is that I have several charts with quite a number of measures - the labels are the same in each of the charts, but the computations for the measures are a bit different in the charts (because of filters, user input, etc). I was hoping that it would be possible to use the labels for coloring, because then I could create a function which retuns the color for each label. If I follow your approach, then I would need a lot of master measures and e.g. changing the color for one of my forecasts would require quite a bit of manual work.

For me it's hard to imagine that there is no easier way to do this.... 

saz
Contributor II
Author

Just in case that someone is facing the same issue: On the following webpage

https://www.datameer.com/blog/qlik-sense-color-by-expression/

there is a way to assign an individual color to each line of the graph; the approach uses a synthetic dimension. Depending on what one is aiming to do one has to decide whether it's more convenient to use master measures (as suggested by @N30fyte ) or a synthetic dimension.