5 Replies Latest reply on Sep 12, 2016 8:05 AM by Simon Runc

    Custom Shape Mark to Fill Bar Graphs


      Had an issue concerning Infogaphics that Forum users did a great job helping.  View example from Simonic below concerning concepts that may be applicable to you.

        • 1. Re: Infographics -- Custom Shape Mark to Fill Bar Graphs
          Dana Withers

          Wow I'd never seen that post but what a wonderful idea - thanks for posting about this!

          I think there are two things that make your data different from the example and therefore difficult to follow/replicate exactly the same.

          1. His data is sum of sales... where for each group he's totalling sales (and pretending they're births) - instead your data does not really sum. You have the star level given - ie group 1 had 4 stars, group 2 has 2,5. I think that following the example you need to sum something in small increments, ie your groups should really "earn their stars at least 0.5 star at a time...I've tried that by creating a little snippet of your data transformed and that does  help.
          2. His graph is big! Big numbers, small increments so lots of little bits. With stars, you really are only going to get 5. That means that the 5 are spread over the entire width of the table and that simply looks a bit too spread out. If you filter the example by South region, you'd see a similar effect: the neatly arranged kids are now spread out a lot and therefore look less like a bar filled. I've worked around that by dragging in the right hand side of the graph so the stars are closer together.

          Since I did not have a picture of half a star, my graph gives 10 stars pretending it is 5.... looks odd but it works sort of.

          Workbook attached... hope that helps.



          • 2. Re: Infographics -- Custom Shape Mark to Fill Bar Graphs
            Simon Runc

            hi Chris,


            The attached is from a post from Joe Mako on how to achieve this. As you can see it's a very clever workaround, and one that I've used myself. The basic idea is that for each star rating (be that a whole star, half star) you give it a position, and then depending on the measure you assign a Shape (either a Whole or Half Star, or empty if you want to fill to 5 stars).


            so for 1 star


            if ([Rating])>=0.875 then 1 else null end


            for 2 stars


            if ([Rating])>=1.875 then 2 else null end


            and so on...


            then the check for half stars


            if round(([Rating]-int([Rating]))*4)=2 then


            else null end


            It takes a bit to set up all the calcs, but once done it's pretty easy to use.


            I went that step further and also did for 1/4 and  3/4 stars!!


            I've attached Joe's original Tableau workbook. I've also attached the Star images I used (in case you don't want to use the ones in the workbook). I downloaded these and then amended in paint.net (not fun...so hopefully this helps you not go through this!!).


            Let me know if you need any extra explanation on how this works

            • 3. Re: Infographics -- Custom Shape Mark to Fill Bar Graphs

              This did the trick.  Thank you Simon.  Deeply appreciated.

              • 4. Re: Custom Shape Mark to Fill Bar Graphs
                Vamsi Immadisetty

                Hi Simon Can you please explain in detail.  I am in same situation. I wanted to display Overall rating of reviews (Single value) and the stars next to that value. Could you please explain step by step approach of attached example. 

                • 5. Re: Custom Shape Mark to Fill Bar Graphs
                  Simon Runc

                  hi Vamsi,


                  So in terms of displaying the Star Rating as a value, and then the Star Rating to be shown as icons this is what the attached does...so Joe has used SUM(Rating) and made it discrete (blue) so it appears as a text header



                  now the tricky part...how does this all work!!


                  So we are unable to simply have a set of 5 stars, where Tableau will 'paint' in the rating, so we (well Joe!) needed to get a bit creative. In the above image, I've unhidden the Columns Header (the x-axis) so you can see what's going on.


                  We are creating a field for each 'potential' star rating, and return for each is the position we are going to place each Star on the axis....


                  Let's look at a couple as an example


                  1 Star Rating

                  if ([Rating])>=0.875 then 1 else null end


                  This looks at the Star rating (say it's a film with a rating of 2.5 stars)...it checks if 2.5 >= 0.875 (so is it at leat one, allowing for rounding), and if true (which it is here) then it assigned the value 1. If not it gets the assignment null. Tableau doesn't (well can't!) plot nulls, so we'd only get a value in position 1


                  2 Star Rating

                  if ([Rating])>=1.875 then 2 else null end


                  Exactly the same, but checks if the Rating is at least 2, and if so returns the value 2. Again this is where this will get plotted on our Axis.


                  3 Star Rating

                  if ([Rating])>=2.875 then 3 else null end


                  Next check fails, as 2.5 isn't >= 2.875, and so returns null, which doesn't get plotted.


                  The next bit if for the part (1/4, 1/2, 3/4 of a star)


                  if round(([Rating]-int([Rating]))*4)=2 then


                  else null end


                  So for our 2.5-star example...we get


                  2.5 - 2 = 0.5 * 4 = 2 does that equal 4. Yes it does so return INT(2.5) = 2 + 1 = 3 and this is where the half star will go.


                  We follow the similar logic for the 1/4, 3/4...and to also complete the Axis position of the blank stars. So in our example, we want a full star for position 1 and 2, a half star for position 3, and empty stars for positions 4 and 5.


                  Once we have all this...we then use measure values on the Columns shelf (and selecting all our Star Rating calculated fields by bringing the measure names onto the filter). We then add measure names on to the Shape tile, and choose the right icon for the right measure. So all the 1,2,3,4,5 (whole) stars get the full-star, No Star measures (for 2,3,4,5) get the empty Star, and then we assign the 1/4, 1/2, and 3/4 star calculated fields to the  1/4, 1/2, and 3/4 star icons.


                  Hope that helps and makes sense. When I first used this technique, I pretty much copied and pasted how Joe had done it (so it worked fine, but I didn't fully understand how), but over time the understanding of how it worked gradually sunk in!

                  1 of 1 people found this helpful