User interaction makes a chart respond to input: hovering over data points, clicking legends, dragging sliders, zooming, or panning. In Altair, it turns a visualization from a fixed display into a space where people can explore data directly. Interactivity is one component of a chart alongside encodings, marks, conditions, compound charts, and configuration. section 3.2.5 section 3.2 section 1.1
Choose interaction according to the chart’s purpose. Exploratory views can give people broad control, but a data story still needs focus. A country comparison, for example, can keep North America visible as the main subject while a drop-down lets the audience select another country for comparison. When the intended message must remain straightforward and consistent, a static chart may be more effective. section 8.4
Two forms of interaction serve different purposes:
- Passive interactivity lets people inspect a chart without changing its state, such as a tooltip or hover effect. section 8.4
- Active interactivity changes the chart in response to input, such as a slider or drop-down menu. section 8.4
- Tooltips can expose selected data columns while preserving a compact visual display. section 3.2.5
An interactive medal chart
Create a pandas DataFrame, encode country and medal counts as bars, add Country, Medals, and Region to the tooltip, then append .interactive(). The resulting chart can be saved as HTML and supports zooming, panning, and point inspection. This is a direct starting pattern; add controls only when they help the audience investigate the question without obscuring the story. section 3.2.5 section 8.4
Listing 3.18 Building an interactive chart in Altair
import altair as alt
import pandas as pd
df = pd.DataFrame(
{"Country": ["Japan", "USA", "Germany", "Spain", "France", "Italy"],
"Medals": [4, 6, 10, 3, 7, 8],
"Region":["Asia","Americas","Europe","Europe","Europe","Europe"]})
chart = alt.Chart(df).mark_bar(color='#636466').encode(
x='Country',
y='Medals',
tooltip=['Country', 'Medals', 'Region']
).properties(
width=300,
title='A bar chart'
).interactive()
chart.save('interactive.html')
Inspect a complete Altair bar-chart pattern that combines tooltip fields with .interactive() and saves the result as an HTML chart. section 3.2.5
Interaction can also support visual context. A two-value menu can highlight a negative salmon trend from 1992–1998 or a positive trend since 1998, allowing the audience to switch the emphasis deliberately. Such controls should reinforce a chosen comparison or message rather than present competing cues without guidance. section 8.7.3 section 8.7.2

