Is there a way to receive click events from charts? #299
-
Let's say I have a pie chart summarizing a table below it of tasks. The pie chart is showing the percentage of done vs not done items. I want to be able to click on the "not done" section of the pie chart and then filter the table to only include "not done" items. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You have this option for the majority of charts. The property is called Click on the bar until you see it is selected; the table should be refreshed accordingly. from taipy.gui import Gui, State
import pandas as pd
data = pd.DataFrame({"values":[60, 40],
"labels":["Done", "Not Done"]})
data_for_table = data
selected = []
md = """
<|{data}|chart|type=bar|y=values|x=labels|selected={selected}|>
<|{data_for_table}|table|>
"""
def on_change(state: State, var_name: str, var_value):
if var_name == "selected":
if len(var_value) == 1:
label = state.data.loc[var_value[0], 'labels']
state.data_for_table = state.data.where(state.data["labels"] == label)
else:
state.data_for_table = state.data
Gui(page=md).run() For your use case with a pie chart, I would suggest using a selector or toggle instead. We will investigate expanding the selected property to pie charts. |
Beta Was this translation helpful? Give feedback.
You have this option for the majority of charts. The property is called
selected
but is unavailable for pie charts. I created a quick example to show you how to use it in a bar chart.Click on the bar until you see it is selected; the table should be refreshed accordingly.