1 Easy Trick to get Clustered Bar Charts
What’s the difference between the two bar views below?
Both bar graphs were created relatively easily in Tableau. The top one is the default. Notice how all the bars are evenly spaced? Not bad.
But notice the bottom chart. It has the bars clustered within each category. That makes it a little easier to compare within the category without sacrificing the ability to compare across categories. So, how do you get that chart? Turns out there’s a easy trick. Remember this trick and you’ll impress your boss and make your fellow Tableau authors jealous.
Here’s the original view:
What’s the trick?
Replace the second dimension on Columns with the continuous (green) field Index().
All you’ll need to do after making the replacement is to right click the Index field and make a couple of adjustments:
- set Compute Using to whatever dimension is defining color
- uncheck “Show Header”
At this point, you might have a little cleanup
- Depending on the size of the chart, you may want to adjust the size of the bars using the Marks card.
- You’ll notice the faint grid lines in the view above. You can remove them (the vertical ones are especially not needed) from the menu “Format” -> “Lines”
Now you’re done! Just remember the 1 easy trick.
Nice tip Joshua. Much easier than some of the alternatives
Interesting trick and have a small question. If the size of the sheet is ‘Fit Width’, how can we accomplish the same. Thank you
The difficulty with this tip is indeed the sizing. “Fit Width” will work in many circumstances as long as that doesn’t make it too wide (or too narrow). You can get extra flexibility with the sizing by placing a constant value on the Size shelf and then editing the size legend.
I tried out what you have mentioned and not much luck when I try to add index the chart type changes and when I change the chart type back to side by side bar…TAbleau goes crazy and does all kinds of things..
Any thoughts please ?
I have attached the files here…
Thanks for your time !
I’ll take a look and let you know what I find…
thx for ur valuable time…here is a quick demo showing what is happening when I am trying it out…
Right after you set the Compute Using of the Index table calc, you have circles for each category. At that point, avoid selecting anything on SHow Me (it’s a great tool for exploring and learning – but it doesn’t often give you the fine control you want to customize a view). Instead, change the Mark Type from Automatic to Bars. Then you can adjust the formatting and Sizing as desired.
thx for the tip, I got it to work but had to increse the cell size a lot which makes the graphs look crazy big…wil try and and see how it goes
It seems something goes wrong when the bars are horizontal. Do you know if is possible to fix that?
It has to do with the way Tableau draws the bars – vertical works because the vertical axis takes precedence over the horizontal axis which is only used for spacing. But, unfortunately it doesn’t work when you flip the axes. I’ll have to go through the archives on my notes and emails because there is something in the back of my mind about a way that someone suggested — but I can’t find it right off…
Hi Joshua, thanks very much for your helpful article. I have the same question as Evaldas, did you ever find out how to do the same thing with horizontal bars?
Based on the way Tableau draws the bars with two axes, it wouldn’t work the same way. But there are other approaches the might allow you to insert some space or gaps between clusters of bars. If dimensions are defining the bars, you might be able to pad the data and insert some blank spaces. If you are using multiple measure, you could try an approach like this: https://vizpainter.com/tableau-quick-tip-create-gap-tabular-reports/
How can I put category name in the bottom of the chart?
Thanks for your time!
That is actually a tough one. Under The Analysis Menu there is an option for Table Layout > Advanced and then a checkbox for showing the innermost level of headers at the bottom when there is a vertical axis. By default that is checked and it sounds like the functionality we want. But in this case, it doesn’t help because the Axis for Index() gets the bottom position and all headers go to the top. I can’t think of any way around this (other than two views put together on a dashboard).
Is it possible to combine a stacked bar chart and side-by-side bars? For example, could the customers be stacked and the categories be side-by-side? Thanks for any help.
Sure! If I’m following you correctly, then what you’d do is place Customer on Color, Category on Columns, and the measure on Rows. That would give you stacked, side-by-side bars. Is that what you mean?
I’m trying to compare two different periods on the same data. I have category A which I’d like to compare the sales of widget1 from 2014 to 2015 side-by-side and sales from widget2 stacked on top for the same years. I’d like to be able to do this with a number of categories with sales of widgets stacked on top. Thanks again.
Could you please help on this
Is it possible to make dimension (categories) will show at the bottom.could not show on top
Interestingly, that’s the subject of the most recent Educational Brain Teaser in the Tableau Forums. I’m waiting on the answer which should come on Friday (see https://community.tableau.com/thread/217704)… I guess we’ll see how it’s done together!
thanks for the trick, however when i what to change the “customer” with Index it turn to vertical bar chart not the side by side bar chart, would you please help me with this?
(when i remove customer the side by side chart turns to vertical bar charts with different colors)
Fara, yes, that’s an issue. It happens because in Tableau the bar marks give the vertical axis priority for the length of bars. If both axes are used, the horizontal gets used for position.
You just saved me a day of researching. Thank you so much for sharing this!!!!!!!!!!!!!!!!!!!!!!!!
Hi, I can’t understand.
Could you help me?
I want insert space between categorize, similar this.
Could you teach me step by step?
If your view is using Measure Names / Measure Values, then it should be similar to what I’ve described. But there may be a complication that is a road block. Or, you may have a completely different setup altogether. Either way, would you be able to share a little more detail about your specific case?
Thanks Joshua, but one question, how can I remove the tick marks?
sorry I missed the last one, I already remove it in format -> Lines. Thanks.