Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
cedfoning
Creator
Creator

Dealing with colors in histogram

hello, i need some help
i want to have an histogram like below : 

cedfoning_0-1646072856203.png

I want to analyse the emissions per item.
The analysis is done for the tracking year and the reference year.
So each item contains 2 years ( tracking year and reference year), so 2 different colors.
How can I do this in Qlik Sense?

Labels (2)
3 Replies
Andrei_Cusnir
Specialist
Specialist

Hello,

 

Perhaps you can use a Bar Chart for this use case scenario, as I believe that it will give you a an output closer to the graph that you have shared. Here are the steps that I have followed:

 

NOTE: You can get the idea behind the logic of the expressions and modify them to implement your specific use case scenario.

 

1. I have used the following load statement:

 

load * inline [
    Category, Year, Value
    CatA, 2019, 100 
    CatA, 2020,    200
    CatB, 2019, 300
    CatB, 2020, 400
    CatC, 2019, 500
    CatC, 2020, 600
];

 

2. For dimensions I have added first the "Category" and then "Year" (Under Data > Dimensions), while for the measure I have used "Sum(Value)"

3. Under Sorting, I have used the order: Category, Year and then Sum(Value)

4. The final and most important step is to custom color the bars within the visualization. For this I went to Appearance > Colors and legend

5. Un-check the Color option to get additional options.

6. Choose "By Expression" and as expression use:

=If(
  Category='CatA'
  If(
    Year='2019'
    '#FBEEE6'
    '#EDBB99'
  ), 
  If(
    Category='CatB'
    If(
      Year='2019'
      '#FEF9E7'
      '#F9E79F'
    ), 
    If(
      Category='CatC'
      If(
        Year='2019'
        '#F9EBEA'
        '#D98880'
      ), 
      '#85929E'
    )
  )
)

 

 

This expression, first checks the Category and then the Year, so it allows us to use different custom color for each bar representing different year in different category. The output looks likes this:

 

IMAGE

 

I hope that this information was helpful. In case I have misunderstood the use case scenario, please elaborate in details by providing additional information. However, if it has helped you resolve the issue, please mark it as accepted solution to give further visibility to other community members. 
 

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

Hello and thank you for your response. 

it works for a very few data like yours

i have a table 

campain:

load * inline[

campaign_id, campaign_year, campaign_reference

1, 2021, 2020

2, 2021, 2019

3, 2021, 2018

];

emission_post: 

load * inline[

emission_id, post

1, post_1

2, Post_2

3, Post_3

];

and a table

gaz: 

load * inline[

gaz_id, campaign_id, total_emission, emission_id

1, 1, 374322,1

2 2, 7983749,2

3, 3, 462873,3

];

Now, i want to have sum(total_emission), per post and per year (campaign_year and campaign_reference) on the same histogram as below : 

cedfoning_0-1646217339814.png

let's say Intrants represents post_1
For post_1, we want to have the sum(tota_emission) for campaign_year and campaign_reference (which is represented with the 2 bars)


Thanks

Andrei_Cusnir
Specialist
Specialist

Hello,

 

I agree with you that the provided solution is not scalable and most probably this workaround can't be used for all the use case scenarios, however this is the closest that I was able to get to your desired outcome. You can try creating the chart in Qlik Sense as you demonstrated in your screenshot without customizing the colors, and then please share here the sample app (with fake data). Someone from Qlik Community might try to modify the chart's configuration to see if there is any other workaround for this issue. 

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