7 Replies Latest reply: Apr 27, 2017 6:16 PM by Brian MacDonald RSS

    Consistent colors across charts

    Brian MacDonald

      This seems like a simple problem but I am having trouble with it.  I want similar measures to have similar colors across two charts in my application.

       

      2017-04-27_11-20-00.jpg

       

      I have tried changing the order of the series in the bar chart. I have "persistent colors" checked in the pie chart.  Nothing seems to work.


      To make matters even more confounding I did some sample data for the last 4 months to post here and that dataset seemed to work the way it should.


      Hoping someone can shed some light here.


      TIA.


       

        • Re: Consistent colors across charts
          Ashwin Lakshmanan

          Hi Brian,

           

          You can force Qlik to assign specific colors by choosing Appearance --> Colors and Legend --> By Expression and then entering a formula in the "Expression" bar. The formula can be something like this:

           

          if(measure='<2', 'blue',

            if(measure='2-12', 'red',

              if(measure='12-24', 'green',

                 if(measure='>24', 'yellow'))))

           

          You can also use hexadecimal colors. For example, in the code above - you can replace 'yellow' with '#daa520'.

           

          If you follow the same procedure in all the charts you want to be consistent with each other, your issue should be solved! Hope this helps!

           

           

          Happy Qlik-ing!

          • Re: Consistent colors across charts
            Brian MacDonald

            Here's the *.qvf with the full data set.  Thanks for your help.

              • Re: Consistent colors across charts
                Ashwin Lakshmanan

                You will have to create a new variable in the Data Load Editor for the different categories. Let us say you create a new variable as follows:

                 

                if(hours_eeg_upload_to_report <=2, '<=2'

                , if(hours_eeg_upload_to_report >2 AND hours_eeg_upload_to_report <=12, '2-12'

                , if(hours_eeg_upload_to_report >12 AND hours_eeg_upload_to_report <=24, '12-24'

                , '24+'))) as hours_eeg_upload_to_report_categories

                ----------------------------------------------------------------------------------------------------------------------

                 

                 

                -Now in the Front End, you can call 'hours_eeg_upload_to_report_categories' as your dimension.

                -Your measure remains the same.

                -In the Colors and Legend --> By Expression, use this following formula:

                 

                if(hours_eeg_upload_to_report_categories = '<=2', 'blue',

                     if(hours_eeg_upload_to_report_categories = '2-12', 'red',

                          if(hours_eeg_upload_to_report_categories = '12-24', 'yellow', 'green')))

                  • Re: Consistent colors across charts
                    Brian MacDonald

                    Sweet, That worked! 

                    The final expression turned out to be:

                    if(hours_eeg_upload_to_report_categories = '<=2', '#4476A9'

                    , if(hours_eeg_upload_to_report_categories = '2-12', '#117833'

                    , if(hours_eeg_upload_to_report_categories = '12-24', '#DDCB75'

                    , '#CB6676')))

                     

                    This site was helpful in getting the color codes

                    Get Colors from Image

                     

                    I tried the same expression in the stacked bar chart but it did not work.  I was forced to match the colors in the bar chart.