Python dict into highcharts条形图数据集

时间:2015-10-20 11:06:06

标签: python dictionary highcharts

我正在构建一个包含我从SQLAlchemy中提取的数据的dict,dict构建正常,但我的问题是使用highcharts将数据放入条形图。

我拥有的是:

__初始化__。PY

@app.route('/dashboard/')
@login_required
def dashboard(chartID = 'chart_ID', chart_type = 'bar', chart_height = 350):
    i = 1
    counts = {}
    counts = build_row_count()
    chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,}
    series = [{"name": counts.keys(), "data": counts.values()}]
    title = {"text": 'Assets'}
    xAxis = {"categories": ['xAxis Data1', 'xAxis Data2', 'xAxis Data3']}
    yAxis = {"title": {"text": 'yAxis Label'}}
    return render_template("dashboard.html", TOPIC_DICT = TOPIC_DICT, row_count=counts, locations=get_locations(), i=i, chartID=chartID, chart=chart, series=series, title=title, xAxis=xAxis, yAxis=yAxis)

dashboard.html

<div id={{ chartID|safe }} class="chart" style="height: 100px; width: 500px"></div>
<script src="http://code.highcharts.com/highcharts.js"></script>
<div id="chart_ID" style="width:100%; height:400px;"></div>
<script>
    var chart_id = {{ chartID|safe }}
    var series = {{ series|safe }}
    var title = {{ title|safe }}
    var xAxis = {{ xAxis|safe }}
    var yAxis = {{ yAxis|safe }}
    var chart = {{ chart|safe }}
</script>

一方面,我可以看到容器,但没有任何内容。所以页面上的所有内容都向下移动了。

页面来源:

<div id=chart_ID class="chart" style="height: 100px; width: 500px"></div>
<script src="http://code.highcharts.com/highcharts.js"></script>

<div id="chart_ID" style="width:100%; height:400px;"></div>
<script>
    var chart_id = chart_ID
    var series = [{'data': [1, 53, 323, 1, 1, 39], 'name': ['MENLYN', 'OR_TAMBO', 'KRUGER_AVE', 'CENTURIONMALL_E1', 'NEDBANK_ATM', 'PRETORIA']}]
    var title = {'text': 'Assets'}
    var xAxis = {'categories': ['xAxis Data1', 'xAxis Data2', 'xAxis Data3']}
    var yAxis = {'title': {'text': 'yAxis Label'}}
    var chart = {'renderTo': 'chart_ID', 'type': 'bar', 'height': 350}
</script>

问题:如何使该dict符合图表数据集/系列格式要求?那是图表没有显示的原因吗?

所以我可以看到dict中的数据正在通过。任何帮助,将不胜感激。

0 个答案:

没有答案