Qlik Community

App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
Read about the latest Qlik Community enhancements on the Community News blog!
cancel
Showing results for 
Search instead for 
Did you mean: 
quintansjoel
Contributor
Contributor

Color assignment in graphs

Hello

For a graph that I have, we have more then 100 products. If I understood correctly, Qlik only assigns 100 different colors unless you take the time in giving each value a different color making use of a master Item. 
For the big picture it isn't that kind of a big deal, but when you make some selections, we have the problem that sometimes, different values use the same color. 
Is there a way that Qlik like change the colors it assigned at first when making some kind of selections so that if the filter narrows the products down to less then 100, they all have a different color? 

Thank you all for your help. 

1 Solution

Accepted Solutions
Andrei_Cusnir
Support
Support

Hello,

 

I was taking a look at this interesting use case scenario and I was able to find a workaround that might work for you. You are right that if you have a lot of data, you will notice that the colors are repeated and I can see how this can be a confusion when you filter data and the fields with the same color appear side by side. In my workaround, I have used the function RGB() [1], and through the script I was able to generated different random combinations of colors for each ID. 

 

For example this is my load script:

 

Data:
LOAD
    OrderID,
    LineNo,
    ProductID,
    UnitPrice,
    Quantity,
    Discount
FROM [...]
(...);

 

As you can see, it is a dataset with data for orders. Now I want to present my data in Charts and at the same time have a different color based on the LineNo field, so I will create a table that will have all the unique LineNo IDs and each ID will be associated with a particular color.

 

So first I am creating a temporary table with all the unique IDs:

 

TempIds:
LOAD
    Distinct LineNo as LineNo
Resident Data;

 

Now I will create a new Colors table which will contain the unique IDs with the random generated values R, G, B:

 

Colors:
Load
    LineNo,
    Floor(Rand() * 256) as R,
    Floor(Rand() * 256) as G,
    Floor(Rand() * 256) as B
Resident TempIds;

 

And then I will drop the temporary table as it is no longer needed:

 

Drop Table TempIds;

 

This process will generate a table that is associated with your data table and will contain the following data:

 

Then you can create a Bar chart and specify the following details:

  1. Under Appearance > Colors and Legends, un-toggle the Colors option
  2. Then from the drop down menu, choose "By Expression"
  3. Inside the expression you can put "=RGB(R,G,B)"
  4. And make sure to check "The expression is a color code"

The results are:

 

 

And since there are many combinations with the RGB codes, it will be very difficult to get an occasion where the color is exactly the same with another field. Additionally, this means that the colors are not repeated, no matter how many values you have.

 

I hope that this information was helpful

 

---

[1] https://help.qlik.com/en-US/sense/August2021/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/ColorFu...

Help users find answers! Don't forget to mark a solution that worked for you! 🙂

View solution in original post

3 Replies
Andrei_Cusnir
Support
Support

Hello,

 

I was taking a look at this interesting use case scenario and I was able to find a workaround that might work for you. You are right that if you have a lot of data, you will notice that the colors are repeated and I can see how this can be a confusion when you filter data and the fields with the same color appear side by side. In my workaround, I have used the function RGB() [1], and through the script I was able to generated different random combinations of colors for each ID. 

 

For example this is my load script:

 

Data:
LOAD
    OrderID,
    LineNo,
    ProductID,
    UnitPrice,
    Quantity,
    Discount
FROM [...]
(...);

 

As you can see, it is a dataset with data for orders. Now I want to present my data in Charts and at the same time have a different color based on the LineNo field, so I will create a table that will have all the unique LineNo IDs and each ID will be associated with a particular color.

 

So first I am creating a temporary table with all the unique IDs:

 

TempIds:
LOAD
    Distinct LineNo as LineNo
Resident Data;

 

Now I will create a new Colors table which will contain the unique IDs with the random generated values R, G, B:

 

Colors:
Load
    LineNo,
    Floor(Rand() * 256) as R,
    Floor(Rand() * 256) as G,
    Floor(Rand() * 256) as B
Resident TempIds;

 

And then I will drop the temporary table as it is no longer needed:

 

Drop Table TempIds;

 

This process will generate a table that is associated with your data table and will contain the following data:

 

Then you can create a Bar chart and specify the following details:

  1. Under Appearance > Colors and Legends, un-toggle the Colors option
  2. Then from the drop down menu, choose "By Expression"
  3. Inside the expression you can put "=RGB(R,G,B)"
  4. And make sure to check "The expression is a color code"

The results are:

 

 

And since there are many combinations with the RGB codes, it will be very difficult to get an occasion where the color is exactly the same with another field. Additionally, this means that the colors are not repeated, no matter how many values you have.

 

I hope that this information was helpful

 

---

[1] https://help.qlik.com/en-US/sense/August2021/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/ColorFu...

Help users find answers! Don't forget to mark a solution that worked for you! 🙂

View solution in original post

quintansjoel
Contributor
Contributor
Author

This works, thanks.
Although it deletes the legend from the graph. Do you maybe know a way so that I can still display the legend and have different colors? 

Andrei_Cusnir
Support
Support

I am glad that it helped you achieve the outcome that you were looking for. Regarding the legend, you are absolutely right that it is hidden with this option. I was checking if there is any way of having the legend there, but I was unable to do so. I have noticed that:

  • For Single color the legend is hidden, because there is no use of it. Since there is only one color displayed.
  • For By dimension the legend is present and you get the option to disable it, if needed. Because now each color represents a different dimension value.
  • For By measure, the legend is present and you also get the option to disable it, if needed. Because each color represents a different range.
  • For By expression, the only options that you have is to set the expression and to set whether the expression is a color or no. You can enable the legend, but only by changing the option "The expression is a color code" off. This means that if you are specifying the color of the bars in the expression then Qlik Sense can't know which values you are representing. This is mainly, because expressions can also be super complicated and can have multiple if conditions. I believe this is the reason that this is not supported and this is a feature request that you can submit by following article [1].

One workaround that you can implement, which is not an optimal solution but it works, is to have a combination of the chart with the Table chart that will act as a legend. In the Table chart you can add the same Dimension as the other chart and in the properties of the dimension you can set the "Background color" to "=RGB(R,G,B)" again. This will mean that you can easily see the value and the color that is representing that value. Even if you do some selections, the Table chart will be updated as well. 

 

For example:

and with selected values:

 

I hope that this information was helpful! 

---

[1] https://community.qlik.com/t5/Knowledge-Base/How-To-Submit-Feature-Requests-For-Qlik-Products/ta-p/1... 

Help users find answers! Don't forget to mark a solution that worked for you! 🙂