问题描述
我在 python 中创建了一个 plotly 折线图,它将被解析到我的 html 文件中。当我使用 fig.show() 打印结果时,没问题。但是当我尝试将其解析为 html 文件时,图表并没有像这张图片那样完美显示:
这是 fig.show() 的图表:
这是代码:
df = pd.read_csv('tes3.csv',header=None,names=["Keyword","Tanggal","Tweet","Sentimen"])
df['Tanggal'] = pd.to_datetime(df['Tanggal'],errors='coerce')
mask = df['Keyword']==que
result = df[mask].groupby([pd.Grouper(key='Tanggal',freq='60s'),'Sentimen']).count().unstack(fill_value=0).stack().reset_index()
result = result.rename(columns={"Keyword": "Jumlah Sentimen","Tanggal":"Waktu"})
time_series = result["Waktu"][result['Sentimen']==0].reset_index(drop=True)
fig = px.line(result,x='Waktu',\
y="Jumlah Sentimen",color="Sentimen")
fig.show()
dataa = [fig]
graphJSON = json.dumps(dataa,cls=plotly.utils.PlotlyJSONEncoder)
return render_template("fortabel.html",headings=headings,data=data,que=que,graph_values=graph_values,layout=layout,graphJSON=graphJSON)
这是 html 文件:
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://d14fo0winaifog.cloudfront.net/plotly-basic.js"></script>
</head>
<div id="chart" class="chart" style="margin-top: 30px; text-align: center;">
<script type="text/javascript">
var graphs = {{graphJSON | safe}};
Plotly.newPlot('chart',graphs,{});
</script>
我该如何解决?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)