Here's the code:
selection = alt.selection_multi(fields=['Priority'])
print(selection)
color = alt.condition(selection,
alt.Color('Priority:N', legend=None, scale=alt.Scale(scheme='category10')),
alt.value('lightgray'))
print(color)
chart = alt.Chart(df_in).mark_point().encode(
x='Acronym',
y='Incident Open Time:T',
color=color
)
chart
Here's the output:
NamedSelection({
selector014: SelectionDef({
fields: ['Priority'],
type: 'multi'
})
})
{'condition': {'selection': 'selector014', 'type': 'nominal', 'field': 'Priority', 'legend': None, 'scale': {'scheme': 'category10'}}, 'value': 'lightgray'}
Javascript Error: Cannot find a selection named "selector014"
What am I missing? thanks.
I think you need to include .add_selection(selection) to your chart definition?
That does work, but would I still do that if I want to use another chart as
a legend? looking at this example in the Altair user guide:
selection = alt.selection_multi(fields=['Origin'])color =
alt.condition(selection,
alt.Color('Origin:N', legend=None),
alt.value('lightgray'))
scatter = alt.Chart(cars).mark_point().encode(
x='Horsepower:Q',
y='Miles_per_Gallon:Q',
color=color,
tooltip='Name:N')
legend = alt.Chart(cars).mark_point().encode(
y=alt.Y('Origin:N', axis=alt.Axis(orient='right')),
color=color).add_selection(
selection)
scatter | legend
On Wed, Apr 10, 2019 at 4:01 PM Jeffrey Heer notifications@github.com
wrote:
I think you need to include .add_selection(selection) to your chart
definition?—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/altair-viz/altair/issues/1425#issuecomment-481863732,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AbxzKRPM2kSx7-b6gaX2LUskw4LEhK_lks5vflEXgaJpZM4coOtB
.
You should call add_selection() on the chart that you want the selection action to take place on.
Got it. Thanks.
On Wed, Apr 10, 2019, 6:28 PM Jake Vanderplas notifications@github.com
wrote:
You should call add_selection() on the chart that you want the selection
action to take place on.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/altair-viz/altair/issues/1425#issuecomment-481909308,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AbxzKaL9qS-rP5aqWY9zW2oO13m1jx5nks5vfnODgaJpZM4coOtB
.
Most helpful comment
I think you need to include
.add_selection(selection)to your chart definition?