【发布时间】:2016-05-24 16:09:57
【问题描述】:
我在使用 Pandas_Highcharts 库显示 Highcharts 时遇到问题。我花了很多时间玩 JSON 输入等,但根本无法显示图表。
每次我在浏览器上加载 /graph 时,我都会收到文本“Test”,但根本看不到任何图表。
使用 Firefox,查看页面源代码(我已经编辑了数据中的各种条目以符合间距)到此:
<html>
<link rel="stylesheet" media="screen" href = "/static/bootstrap.min.css">
<meta name="viewport" content = "width=device-width, initial-scale=1.0">
<head>
<script type="text/javascript" src="http://ff.kis.scr.kaspersky-labs.com/1B74BD89-2A22-4B93-B451-1C9E1052A0EC/main.js" charset="UTF-8"></script></head>
<body>
<p> Test </p>
<div id="my-chart"></div>
<script type="text/javascript">
new Highcharts.Chart({"series":[{"data":[[1462838400000,2158372.6420299998],[1462752000000,1438419.8610100001],[1462665600000,667993.263726],[1462579200000,1825474.7086099999],[1462492800000,1908047.6404200001], [1304985600000,228989.8988]],"name":"Value","yAxis":0}],"yAxis":[{}],"chart":{"renderTo":"my-chart"},"xAxis":{"type":"datetime","title":{"text":"Date"}},"legend":{"enabled":true}});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</body>
</body>
<script type = "text/javascript" src = "/static/bootstrap.min.js"></script>
</html>
Pandas Higcharts:https://github.com/gtnx/pandas-highcharts 这一切看起来都很简单,但为什么我不能让它工作。
我不明白为什么以下代码停止工作: 我的相关 graph.html 页面:
<html>
<link rel="stylesheet" media="screen" href = "/static/bootstrap.min.css">
<meta name="viewport" content = "width=device-width, initial-scale=1.0">
<head>
</head>
<body>
<p> Test </p>
<div id="my-chart"></div>
<script type="text/javascript">
new Highcharts.Chart({{chart|safe}});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
</body>
</body>
<script type = "text/javascript" src = "/static/bootstrap.min.js"></script>
</html>
我的烧瓶 python 文件包含相关的@app.route('/graph')
from flask import Flask, render_template, request
import pandas as pd
import pandas_highcharts.core
app = Flask(__name__)
@app.route('/graph')
def graph_Example(chartID = 'chart_ID', chart_type = 'line', chart_height = 500):
df = pd.read_csv('csv/BCHAIN-TRVOU-BitcoinUSDExchangeTradeVolume.csv', index_col='Date', parse_dates='Date')
dataSet = pandas_highcharts.core.serialize(df, render_to='my-chart', output_type='json')
return render_template('graph.html', chart=dataSet)
一般来说,我有各种使用 Pandas 生成的 DataFrame。我的问题只是现在能够用 HighCharts 显示它们。 我的 CSV 文件也位于此处:https://drive.google.com/open?id=0B8xdmDmZgtJbVkhCcjZkZUhaajg
本质上,我想绘制每个 CSV 文件,然后将某些值与其他值进行对比(例如,美元价格与比特币总量的关系)。这就是我使用 Pandas DataFrame 的原因。
任何帮助将不胜感激:)
【问题讨论】:
-
怎么了?显示错误消息或不正确的输出。
-
内部服务器错误消息。我只需要一些关于如何使用烧瓶正确实现 pandas_highcharts 的指导帮助。我似乎无法找出正确的方法。
-
在调试模式下运行您的 Flask 应用程序(
app.run(debug=True)而不仅仅是app.run()),再试一次,然后粘贴完整的回溯。 -
好的,我已经修复了一个小错误,但已经在客户端发布了我收到的页面源代码。可以看到 JSON 数据传递成功,但没有显示图表。
标签: jquery python pandas highcharts flask