Text labeling not matching stacked bar chart
See original GitHub issueHello there and thanks for this great framework! I have an issue with the following bar chart: Click
Note that I added the red rectangle to highlight a problem: some text labels do not match the bar below. So in this case the 55% and the 41% should be switched around. When I enable tool tips then I can see that the correct value is actually used by altair for the bar plot but not for the label. Strangely enough this only happens for some values…
It is created by this code:
base = alt.Chart().mark_bar().encode(
x=alt.X("value:Q", stack='normalize',axis=alt.Axis(format='%', title='Percentage Reacted Normalized')),
y=alt.Y(md_db.param_boxize+':O', axis=alt.Axis(title='Box Size')),
tooltip=['value', 'value_norm:Q', 'value_ref_ratio:Q','variable:N', md_db.param_boxize+ ':O'] + [md_db.param_react + str(n) + ':N' for n in range(2)],
)
bars = base.encode(
color=alt.Color('variable:N'),
)
text = base.mark_text(
dx=-10,
angle=0,
color='black',
).encode(
text=alt.Text('value_norm:Q',format='.0%'),
)
alt.layer(bars, text).facet(
column=alt.Column('type:N'),
row=alt.Row(md_db.param_diff_col+':N', header=alt.Header(labelAngle=0)),
data=df_merge
)
Unfortunately I cannot attach dummy data right now but will do so if requested.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Why does the stacked bar chart not match values in table?
(Another hint is that the text looks "overplotted" -- this is because every character is being printed once for each row in the...
Read more >Labeling stacked bar charts shifts when adding color to text
I'm trying to add labels to a stacked bar chart but when I try to change the colors of the text, the numbers...
Read more >Edit titles or data labels in a chart - Microsoft Support
On a chart, click the chart or axis title that you want to link to a corresponding worksheet cell. · On the worksheet,...
Read more >Formatting (position) of labels for stacked bar chart
I thought that placing them beside the bar would increase legibility. However, I am not sure if the different thickness of the bars...
Read more >Column Chart Component - Appian 22.3
Displays a help icon with the specified text as a tooltip. The tooltip displays a maximum of 500 characters. The help icon does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For what it’s worth, here’s how you can push the data manipulations into the chart’s transform specification:
I think that error indicates that you’re using Altair version 3.0. Update to the latest release (3.1), and the code should work.
If you need to stick with Altair version 3.0 for some reason, you can specify the data in the
facet
method, as you did in your original snippet.