The best practices say that a designer should avoid using bar charts with multi-colored bars or having too many colors in any of your chart objects. But at times, we need to cater to the demands of the organization and take an uncalled for approach to designing. The following recipe explains how to associate distinct field values to different colors in the Qlik Sense script.
This recipe serves to be a good example to demonstrate the use of Pick
function in the script. Use the following steps to get started:
Persistent Colors
.Actuals
and Budget
of four products. The script is available for download on the Packt Publishing website:ProductsTemp: LOAD * INLINE [ Product, Actuals, Budget Footwear, 100000, 120000 Tyres, 180000, 150000 Mountain Bikes, 250000, 195000 Road Bikes, 200000, 225000 ]; Products: LOAD *, pick(match("Product", 'Footwear', 'Tyres', 'Mountain Bikes', 'Road Bikes'), RGB(236,129,0),RGB(250,185,0), RGB(70,137,164), RGB(141,25,8)) as "Product color" RESIDENT ProductsTemp; Drop table ProductsTemp;
Actuals
.=[Product color]
The Pick
function used in the script links values in the Product
field to distinct RGB values. Each product is displayed in a different color bar when the Product color
field is used in the color expression of the chart.
Persistent colors can also be obtained through the chart properties when we select the colors by dimension. However, using this approach we can't have custom colors but have to depend on the color scheme in Qlik Sense.