5 Replies Latest reply on Nov 26, 2018 6:14 AM by Abhimanyu Garg

    IMPORTANT: Dynamic Custom Branding / Colors In Tableau (Is It Possible?)

    Abhimanyu Garg

      Hi All.

       

      I have a client dashboard where I show some charts and tables and these are filtered on advertiser level (single select filter). Currently I am using the same set of colors for all advertisers across all the charts.

       

      Now, the requirement is to change these chart colors dynamically based on the selected advertiser. For testing purposes I am implementing in the following manner (for a chart which contains both negative and positive values):

       

      1. Create a calculated which looks for advertiser value and the metric value (being displayed in chart) using IF conditions.

      2. For advertiser: abc and metric value <0 assign a unique identifier like abc_negative.

      For advertiser: abc and metric value >=0 assign a unique identifier like abc_positive.

      3. Write similar IF conditions for rest of the advertisers. Once this step is done, drag and drop this calculated field in the color mark and one by one select an advertiser and manually assign both the negative and positive color hex values for them.

      4. Repeat this process for all the advertisers one by one.

       

      I have tested this calculated field solution for a limited number of advertisers and it is working fine. But the main problem is that this process is entirely manual and is not scalable as the number of advertisers will keep on increasing in the future. Also, if I have to change a color even for one of the existing advertisers, I will need to manually make this change in desktop and then re-publish the dashboard.

       

      To resolve this, I am planning to create a mapping table which contains all the advertiser ids and their respective 2 or 3 colors and then use this table to assign the colors in tableau's color shelf. But over here as well I need to manually select the color values for every advertiser one by one even though the mapping table consists of all the hex codes properly.

       

      1. Is there a way to make the color shelf in tableau desktop automatically pick all the colors based on the selected advertiser?

      2. Also lets say I change colors for an existing advertiser in the mapping table, is it possible that the published dashboard automatically picks the new colors without the need of republishing?

      3. Similarly, if I add a new advertiser and it's respective colors in the mapping table, is it possible for the dashboard to automatically pick up these colors in all the charts present?

       

      I am trying various things like:

       

      1. Use a advertiser to color mapping table. This solution will not require a huge calculated field but still I would need to manually assign colors in the color shelf.

      2. Same goes with other kinds of data sources like excel sheet, google sheet, etc.

      3. I tried to explore REST API functionality as well but I am not able to understand how to automatically change the color in the charts based on the hex codes passed by REST API. I can pass the hex code values but since color shelf is internal to the dashboard, ! am not able to dynamically change charts' colors.

      4. Same thing goes with Web Data Connector functionality.

       

      Is it possible to implement this requirement?

       

      It would be great if anyone could help me with this.

        • 1. Re: IMPORTANT: Dynamic Custom Branding / Colors In Tableau (Is It Possible?)
          Shinichiro Murakami

          Please attach mocked up sample data as twbx.

           

          Thanks,

          Shin

          • 2. Re: IMPORTANT: Dynamic Custom Branding / Colors In Tableau (Is It Possible?)
            Abhimanyu Garg

            Thanks for your reply Shin.

             

            Please find the attached twbx file which contains a sample data of 2 Advertisers:

            1. abc

            2. xyz

             

            I have created a calculated field called CUSTOM COLOR and applied the following logic over there:

            if [Advertiser] = 'abc' and [Metric Value] < 0 then 'abc_negative'

            ELSEIF [Advertiser] = 'abc' and [Metric Value] >= 0 then 'abc_positive'

            ELSEIF [Advertiser] = 'xyz' and [Metric Value] < 0 then 'xyz_negative'

            ELSEIF [Advertiser] = 'xyz' and [Metric Value] >= 0 then 'xyz_positive'

            END

             

            And then used this field in the color shelf to manually assign the following colors by selecting the advertiser one by one.

            1. abc_negative color: #da291c

            2. abc_positive color: #9e3768

            3. xyz_negative color: #a2cc6f

            4. xyz_positive color: #24293d

             

            Now as soon as I change the advertiser (from it's filter), the custom colors will be displayed in the chart.

             

            I will get back to you with the color mapping table solution in a while. Let me know your thoughts about this one.

            • 3. Re: IMPORTANT: Dynamic Custom Branding / Colors In Tableau (Is It Possible?)
              Shinichiro Murakami

              Not exactly sure, but with this calc, new color should be assigned automatically.

               

               

              To assign specific color, you need to touch source code, I believe.

              Save the file as TWB (not TWBX), then open the TWB file with notepad++ or other text tool.

               

              Find color setting code, and assign HEX code.

               

              I don't know the way to automate this source code change.

               

               

              Thanks,

              Shin

              • 4. Re: IMPORTANT: Dynamic Custom Branding / Colors In Tableau (Is It Possible?)
                Abhimanyu Garg

                Thanks Shin for this.

                 

                Yeah I have tried a similar solution for this before (by changing the colors directly in the xml file). For local use it is fine but yeah for published dashboards it wont work (in an automated way).

                 

                Thanks a lot for this. Let me know if you find anything else on this. I will do the same if I find another solution. Thanks.

                • 5. Re: IMPORTANT: Dynamic Custom Branding / Colors In Tableau (Is It Possible?)
                  Abhimanyu Garg

                  Hi Shin.

                   

                  I got a new solution for my problem statement. The following steps are involved:

                  1. Create a lookup table which contains advertiser to color mapping. This table includes individual R,G,B values of both negative and positive color.

                  2. Create a color palette in Preferences.tps file which contains all the possible hex codes (with a 5 step interval). Like if the first color in the palette is #000000 (or RGB(0,0,0)), then the second color will be #000005 (or RGB(0,0,5)) and so on! This palette contains 140608 hex codes (52*52*5) precisely.

                  3. Create a calculated field in tableau workbook as follows:

                  If Metric Value  < 0  then

                  ROUND(AVG(Negative R Value)/5)*52*52 + ROUND(AVG(Negative G Value)/5)*52 + ROUND(AVG(Negative B Value)/5)

                   

                   

                  ELSE IF Metric Value >= 0 then

                  ROUND(AVG(Positive R Value)/5)*52*52 + ROUND(AVG(Positive G Value)/5)*52 + ROUND(AVG(Positive B Value)/5)

                   

                   

                  End

                  In this calculated field, we are taking R,G,B values (both for negative and positive color) from the mapping table and converting it to a unique number.

                  4. Drop this calculated field on color tab and assign the previously created palette to this.

                  5. Now as the user changes the advertiser, if that advertiser is present in the mapping table with proper RGB values, then the dashboard will automatically display the correct colors.

                   

                  You can go through the attached twbx file. This solution can be extended to multiple advertisers and this won't require any kind of manual work. Let me know your thoughts about this.