This blog series is a weekly AlteryxTips blog that will provide you with Alteryx tips every week.
This is an application of the technique from the previous post. For this, you need to create a bit complex workflow. In this post, I would like to explain how to add the total label to the stacked bar chart.
Normal Stacked Bar chart
You can create the stacked bar chart with multiple items as follows in the Interactive Chart tool of Alteryx.

The bar chart is divided by the items “potato”, “banana” and “apple” in the Item field. To do this, you can use the “Split” option on the Transforms tab.

And also set some options.
- Bar Mode : Stack
- Text : sales field (This is for the label field)
- Text Position : Inside

But there is no option for the total label anyway.
Do the same as for the previous post
At the previous post, I explained about adding the label to the line chart using overlay the transparent bar graph. But at this post, I’m trying to add the label to the bar chart. The important point is that the “Bar Mode” is synchronized with all bar graphs. However I wanted to use “Overlay Mode” regarding to the transparent bar chart to add label. When I change the Bar Mode from “Stacked” to “Overlay” at the transparent bar layer, it will destroy the charts.

So, I change the way to use the Overlay Mode, not to use the Stacked Mode.
The correct way
To express the stacked bar chart and total label, you have to make all them by “Overlay Mode”. For that, you have to calculate the value as stacked position in advance. In this case, the image is as follows.

The specific steps are as follows.
Preparation for the total label
In this case, you can use the Running total tool or the Multi-Row Formula tool. The original data is as follows.

Put the Running Total tool and set the “sales” field as “Create Running Total” with group by “store” field as follows.

After that, you can get the data like this.

“RunTol_sales” field is the position of the bar chart on the Interactive Chart tool. The important point is the order of the records. In other words, the chart is rendered from the data at the top pf the record. So, you have to sort the data decending using the Sort tool as follows.

Draw the bar chart
Basic setting
First, add the Total layer for the total label as follows.
- Type : Bar
- X : store
- Y : RunTot_sales

Next, add the main bar chart. The setting for “Item” layer is as follows, which is the same as the “Total” layer setting.

And then, use the split option for the Item layer at the Transform tab.

Draw the total label chart
Next, set the chart options at the Layer tab.
- Bar Mode : Overlay
- Text : RunTot_sales
- Text Positoin : Outside (This makes the label position to top position.)

In this case, it doesn’t need to change the Opacity because it is hidden by another bar chart.
Set the bar chart for each item
Finally, all separated items(potato, banana and apple) should be set as follows.
- Text : sales
- Text Position : Inside

The most important point is not to set the “Tot_sales” but “sales” for “Text”. “Tot_sales” is only set for the vertical position on the chart.
The screenshot above is for “potato” layer. You need to set the same setting for the others.
Finally, you can get the stacked bar chart with total label as follows. Congratulations!

Conclusion
- I have explained how to create the stacked bar chart with the total label.
- In this case, you have to prepare the data in advance.
Sample workflow download
The next blog post is …
The next post will be a part of this series. I will explain how to add the number at the pie chart.
コメント