I tried to have stacked bars (columns) charts with a trend line above.
Right now with below codes I was able to have a line charts
How may I change it to have line charts? (Sorry for some Japanese wordings included)
def chart_returns_different_country(bq): count_list = ['民生用電気機器', '重電機器受注生産品'] field_list = ['Refridgerator','Refridgerator Larger than 401 Litre','Automobiles equipment','Construction equipment'] input_1 = widgets.Dropdown(options = count_list, value = '民生用電気機器', description = 'Choose a category', style={'description_width': 'initial'}, layout=Layout(width='50%', height='40px') ) input_2 = widgets.Dropdown(options = field_list, value='Refridgerator', description='機器') start_time = date(2020, 4, 30) input_3 = widgets.DatePicker(description='Choose start date', disabled=False, value=start_time) end_time = datetime.today() input_4 = widgets.DatePicker(description='Choose end date', disabled=False, value=end_time)民生用電気機器_電気冷蔵庫 ={'House Appliance Refridgerator': 'JNESHQER Index'}民生用電気機器_電気冷蔵庫うち401L以上 = {'House Appliance Refridgerator Over 401 Litre':'JNESHQRO Index'}重電機器受注生産品_自動車 = {'Heavy Electric Equipment - Automobiles': 'JPCITOTL Index'}重電機器受注生産品_建設業= {'Heavy Electric Equipment - Construction':'JNHECONS Index'} field_0 = {'Refridgerator' : 民生用電気機器_電気冷蔵庫,'Refridgerator Larger than 401 Litre' : 民生用電気機器_電気冷蔵庫うち401L以上, 'Automobiles equipment' : 重電機器受注生産品_自動車,'Construction equipment' : 重電機器受注生産品_建設業} fig = go.Figure() #fig.update_layout(barmode = 'stack') fig.update_traces(textfont_size=18, textangle=0, textposition ="outside", cliponaxis =False) fig.layout.xaxis.title.text = 'Date' fig.layout.yaxis.title.font.size=18 fig.update_layout(template ='plotly_dark',height=700) fig.update_layout(xaxis={'side':'bottom'}) fig.update_xaxes(tickfont_size=18, tickangle=0) fig.update_yaxes(tickfont_size=18) fig.update_layout(xaxis=dict(showgrid=False), yaxis=dict(showgrid=False)) fig = make_subplots(specs=[[{"secondary_y": True}]]) fig_w = go.FigureWidget(fig) def update_chart(evt=None): global field_0 global data_item if input_1.value == "民生用電気機器": field_0 = {'Refridgerator' : 民生用電気機器_電気冷蔵庫,'Refridgerator Larger than 401 Litre' : 民生用電気機器_電気冷蔵庫うち401L以上} else : field_0 = {'Automobiles equipment' : 重電機器受注生産品_自動車,'Construction equipment' : 重電機器受注生産品_建設業} data_item = {'Value': bq.data.px_last(dates=bq.func.range(input_3.value, input_4.value),fill='NA',per='M')} #currency='USD' selected_index = field_0.get(input_2.value) global bql_request bql_request = bql.Request(list(selected_index.values()), data_item) df = bql.combined_df(bq.execute(bql_request)) df.index = df.index.map(dict(zip(selected_index.values(), selected_index.keys()))) df = df.reset_index() df = df.pivot(index='DATE', columns='ID', values='Value') df_plot = df.copy() df_plot.reset_index(inplace=True) df_plot.set_index('DATE', inplace=True) x = df_plot.index fig_w.data= [] for i in range(len(df_plot.columns.values)): if i == 0: fig_w.add_trace(go.Scatter(name= df_plot.columns.values[0], x= x, y= df_plot[df_plot.columns.values[0]], mode='lines', yaxis='y1'), secondary_y=False) fig_w.add_trace(go.Bar(name= df_plot.columns.values[0], x= x, y= df_plot[df_plot.columns.values[0]], mode='lines', yaxis='y1'), secondary_y=False) else: try: fig_w.add_trace(go.Scatter(name=df_plot.columns.values[i], x= x, y= df_plot[df_plot.columns.values[i]], mode='lines', yaxis='y2'), secondary_y=True) fig_w.add_trace(go.Bar(name=df_plot.columns.values[i], x= x, y= df_plot[df_plot.columns.values[i]], mode='lines', yaxis='y2'), secondary_y=True) # fig_w.set_ylabel('Others', color = 'r') except: pass y_label1 = df_plot.columns.values[0] y_label2 = 'Others' fig_w.update_layout(yaxis = dict(title = y_label1), yaxis2 = dict(title = y_label2)) fig_w.layout.xaxis.title.text = 'Date' fig_w.update_xaxes(tickangle=45) fig_w.update_layout(template='plotly_dark', height=700, font_family="Arial", legend_font_size=16, font=dict( family="Arial", size=18, )) fig_w.update_layout(xaxis=dict(tickvals=x)) fig_w.for_each_xaxis(lambda x: x.update(showgrid=False)) fig_w.for_each_yaxis(lambda x: x.update(showgrid=False)) update_chart() input_1.observe(update_chart, names='value', type='change') input_2.observe(update_chart, names='value', type='change') input_3.observe(update_chart, names='value', type='change') input_4.observe(update_chart, names='value', type='change') bql_request =[str(bql.Request(list(field_0.get('Refridgerator').values()), data_item)), str(bql.Request(list(field_0.get('Refridgerator Larger than 401 Litre').values()), data_item)), str(bql.Request(list(field_0.get('Automobiles equipment').values()), data_item)), str(bql.Request(list(field_0.get('Construction equipment').values()), data_item))] return {'Chart': widgets.VBox([input_1, input_2, input_3, input_4, fig_w]), 'BQL Query': '\n'.join(bql_request)}chart_returns_different_country(bq)['Chart']I have tried fig.add_trace(go.Bar() but did not work