Black Lives Matter. Please consider donating to Black Girls Code today.

Customdata in Bar graphs

I am not able to add custom data to a Bar graph. I have the main bar graph and if I click on any of the bars of the main graph I need to update another bar graph from the custom data that I obtain from the main graph.

The below snippet is what I am using for adding customdata:

def update_bar_graph(categories):
if categories is None or categories==[]:
categories=gbp_name
data_map= [
go.Bar(
x=categories,
y=df[i],
#customdata=i,
text=i,
name=i
)for i in day_detail
]
return{
‘data’:data_map,
‘layout’:
go.Layout
(
title=‘GBP vs Days Chart’,
yaxis={‘title’:‘Number of alerts’},
barmode=‘group’,
hovermode=‘closest’
)
}

The error that I get is:

Valid attributes for ‘bar’ at path [] under parents []:

['bardir', 'base', 'basesrc', 'dx', 'dy', 'error_x', 'error_y',
'hoverinfo', 'hovertext', 'hovertextsrc', 'insidetextfont',
'legendgroup', 'marker', 'name', 'offset', 'offsetsrc', 'opacity',
'orientation', 'outsidetextfont', 'r', 'rsrc', 'showlegend', 'stream',
't', 'text', 'textfont', 'textposition', 'textpositionsrc', 'textsrc',
'tsrc', 'type', 'uid', 'visible', 'width', 'widthsrc', 'x', 'x0',
'xaxis', 'xcalendar', 'xsrc', 'y', 'y0', 'yaxis', 'ycalendar', 'ysrc']

Can anyone please tell how to add customdata to go.Bar()?

For now, try getting around the validation step by just replacing go.Bar with a dict. This looks like it is a bug with go.Bar

1 Like

Thanks for the reply @chriddyp . But when this gets plotted I am getting a Scatter Plot instead of a Bar graph.
How do I resolve that problem.

@deepuranganathan did you add type = 'bar'?

data_map= [
   dict(
      type = 'bar',
      x=categories,
      y=df[i],
      customdata=i,
      text=i,
      name=i
   ) for i in day_detail
]
2 Likes