这是我的烧瓶应用程序的代码。我想在我的网页上显示绘图但它没有显示。
蟒蛇:
@trade.route('/',methods=["POST", "GET"])
def search():
if request.method == 'POST':
symbol=str(request.form['symbol']).upper()
if finnhub_client.company_profile2(symbol=symbol) == {} or symbol=='':
flash('Invalid symbol!', category='error')
information = dict(finnhub_client.company_profile2(symbol=symbol))
url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol='+symbol+'&outputsize=full&apikey=HCWSV4D09YCJ1DKT'
r = requests.get(url)
data = r.json()
date = data['Time Series (Daily)']
high = [float(data['Time Series (Daily)'][x]['2. high']) for x in date]
fig = px.line(data, x=data['Time Series (Daily)'].keys(), y=high, title='Time Series with Range Slider and Selectors', color_discrete_sequence=px.colors.qualitative.Set1)
fig.update_xaxes(
rangeslider_visible=False,
rangeselector=dict(
buttons=list([
dict(count=1, label="1m", step="month", stepmode="backward"),
dict(count=6, label="6m", step="month", stepmode="backward"),
dict(count=1, label="YTD", step="year", stepmode="todate"),
dict(count=1, label="1y", step="year", stepmode="backward"),
dict(step="all")
])
)
)
# Define the buttons first
buttons = [
dict(
args=[{"yaxis.range": [min(high), max(high)]}],
label="Full",
method="relayout"
),
dict(
args=[{"yaxis.range": [min(high), max(high) * 0.75]}],
label="75%",
method="relayout"
),
dict(
args=[{"yaxis.range": [min(high), max(high) * 0.5]}],
label="50%",
method="relayout"
),
dict(
args=[{"yaxis.range": [min(high), max(high) * 0.25]}],
label="25%",
method="relayout"
),
]
# Update the updatemenus with the defined buttons
fig.update_layout(
updatemenus=[dict(buttons=buttons, direction="down", showactive=True)]
)
return render_template("try.html",information=information,fig=fig)
html代码:
{% extends "base.html" %}
{% block content %}
<div id='chart' class='chart'>hiiii</div>
<script type='text/javascript'>
var graphs = {{fig | safe}};
Plotly.plot('chart',graphs,{});
</script>
{% endblock %}
在“base.html”文件中,我在头部添加了这些脚本:
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
我在 html 页面中遇到错误: 预期的财产分配。 预期的声明或声明。 ','预期。