Skip to content Skip to sidebar Skip to footer

Altair - Unable To Get Tooltips For One Layer In A Line Chart

When I plot a layered chart consisting of two groups of lines, the tooltips in one layer do not show up. This also occurs in the VL editor. Any insight to why this is happening wou

Solution 1:

as mentioned by @campo in comments you must use interactive separately for each chart.

Now both tooltips will show up.

df=pd.DataFrame({'school_code': ['AQUI', 'Board'] * 5, 'y4_rate': [.1, .2, .3, .4, .5, .1, .2, .3, .4, .5],
                  'cohort_year': ['1', '1', '2', '2','3', '3', '4', '4', '5', '5']})

sch=alt.Chart(df).mark_line(point=True).encode(
    x=alt.X('cohort_year', axis=alt.Axis(labels=False)),
    y=alt.Y('y4_rate', axis=alt.Axis(format='.0%'), title='Percentage of Students'),
    color=alt.Color('school_code', title=None, legend=alt.Legend(labelFontSize=15, titleFontSize=20)),
    tooltip=[alt.Tooltip('y4_rate', title='percentage of students', format='.0%')]
).transform_filter(alt.datum.school_code != 'Board').interactive() #<<< Here

brd=alt.Chart(df).mark_line(point=True).encode(
    x=alt.X('cohort_year', axis=alt.Axis(labels=False)),
    y=alt.Y('y4_rate', axis=alt.Axis(format='.0%'), title='Percentage of Students'),
    color=alt.Color('school_code', title=None, legend=alt.Legend(labelFontSize=15, titleFontSize=20),scale=alt.Scale(range=['black'])),
    tooltip=[alt.Tooltip('y4_rate', title='percentage of students', format='.0%')]
).transform_filter(alt.datum.school_code == 'Board').interactive() #<<< Here


alt.layer(sch, brd).resolve_scale(color='independent').properties(
   width=700, height=400
   )  #.interactive() # commented out this.

Post a Comment for "Altair - Unable To Get Tooltips For One Layer In A Line Chart"