Click data does not include 'text' attribute

I want to use the text variable to update a graph. In one of your examples clickData included text.Is there a way to include text in my clickData? See below your example:

{
“points”: [
{
“pointNumber”: 0,
“customdata”: “c.w”,
“y”: 9,
“x”: 1,
“pointIndex”: 0,
“curveNumber”: 1,
“text”: “w”
}
]
}

Mine only displays:
clicked data =

{
‘points’: [
{
‘curveNumber’: 104,
‘pointNumber’: 3,
‘pointIndex’: 3,
‘x’: ‘201915’,
‘y’: 100
}
]
}

I had this same issue and it took me SO LONG to figure out what was going on. So in order for the clickData to have text, the size of the arrays being plotted must match the size of the array being sent to the text field. So for example, if I wanted to create a vertical line at a specific time in a scatter plot, here is an example of code that would NOT have the text information in the clickData:

fig = {}
fig.add_trace(go.Scattergl(
x=A[‘time’],
y=A[‘values’],
mode=‘markers’,
name = ‘Data’,
text = A[“Info”], # this would get included in the clickData
hoverinfo = ‘text’,
),
)

# Add vertical overlay
overlayMask = A['values'] > 1000 # assume for this example this only identifies one point
fig.add_trace(go.Scattergl(
            x=[A[mask]['time'], A[mask]['time']],
            y=[A['values'].min(), A['values'].max()],
            mode='lines',   
            name = 'Overlay',
            text = A[mask]['time'].astype(str), # This would NOT be included in the clickData
            hoverinfo = 'text',
        ),
        )

The reason the second trace would not have the text entry in the clickData is because A[mask][‘time’] is length 1 while the x for that trace is length 2.

This would fix it:
fig = {}

Plot data points

fig.add_trace(go.Scattergl(
x=A[‘time’],
y=A[‘values’],
mode=‘markers’,
name = ‘Data’,
text = A[“Info”], # this would get included in the clickData
hoverinfo = ‘text’,
),
)

# Add vertical overlay
overlayMask = A['values'] > 1000 # assume for this example this only identifies one point
fig.add_trace(go.Scattergl(
            x=[A[mask]['time'], A[mask]['time']],
            y=[A['values'].min(), A['values'].max()],
            mode='lines',   
            name = 'Overlay',
            text = [A[mask]['time'].astype(str),A[mask]['time'].astype(str)], # Now that this is the same length as x, this text will be included in the clickData
            hoverinfo = 'text',
        ),
        )
1 Like