【发布时间】:2020-01-06 03:41:09
【问题描述】:
我正在尝试使这两个图表具有响应性,以便如果我突出显示一个选择并放大其中一个,另一个图表会在同一日期放大。
例如,在我发布的第一张图片中,如果我在 1 月份放大一个图表,我希望另一个图表也在同一日期范围内放大。
您可以在我附上的图片中看到我想要做什么。
谁能帮帮我?
import dash
import dash_core_components as dcc
import dash_html_components as html
import ssl
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
ssl._create_default_https_context = ssl._create_unverified_context
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
app.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
html.H1(
children='graph1',
style={
'textAlign': 'center',
'color': colors['text']
}
),
html.Div(children='Displaying Apple High and Low.', style={
'textAlign': 'center',
'color': colors['text']
}),
dcc.Graph(
id='example-graph-2',
figure={
'data': [
{'y': df['AAPL.Open'], 'x': df['Date'], 'type': 'line', 'name': 'Activity'},
{'y': df['AAPL.High'], 'x': df['Date'], 'type': 'line', 'name': 'Baseline'},
],
'layout': {
'plot_bgcolor': colors['background'],
'paper_bgcolor': colors['background'],
'font': {
'color': colors['text']
}
}
}
),
html.Div(children='Second Graph (Volume).', style={
'textAlign': 'center',
'color': colors['text']
}),
dcc.Graph(
id='graph2',
figure={
'data': [
{'y': df['AAPL.Volume'], 'x': df['Date'], 'type': 'bar', 'name': 'Volume'},
],
'layout': {
'plot_bgcolor': colors['background'],
'paper_bgcolor': colors['background'],
'font': {
'color': colors['text']
}
}
}
),
])
if __name__ == '__main__':
app.run_server(debug=True)
【问题讨论】:
标签: python plotly-dash