简体   繁体   中英

How to make bar chart interactive on both x and y axis using altair

How to make bar chart interactive. I mean I want to scroll both x-axis and y-axis.

I have pasted code below,

import altair as alt
import pandas as pd
df = pd.read_csv('graph.csv')
alt.Chart(df).mark_bar(orient='vertical').encode(
x = alt.X('SWIPE_START_DATETIME'),
x2 = alt.X2('SWIPE_END_DATETIME'),
y='NO_OF_HOURS',
tooltip=['SWIPE_START_DATETIME','SWIPE_END_DATETIME','NO_OF_HOURS']
).interactive()

I am able to scroll along one axis using above code.

Can someone help me modify the code

The answer to this is the same as the answer to the question you posted yesterday .

Vega-Lite, the renderer used by Altair, does not support panning/zooming on nominal or ordinal axes. If adding .interactive() doesn't work, it indicates that your data is nominal or ordinal.

If your columns contain strings representing temporal data, you can use :T in the encoding to ensure that it's treated as a time rather than as a string category.

Otherwise, there are hacky workarounds you can do (as in my answer to the linked question), but fundamentally the issue is Vega-Lite does not support panning/zooming of nominal or ordinal axes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM