无法使我的图表使用mongoDB中的数据

问题描述 投票:-1回答:1

我无法显示包含来自mongoDB的数据的图表。我正在使用Python,Flask,chartJS和mongoDB

请耐心等待,这里是菜鸟

我的程序:

PYTHON

import pymongo
from datetime import datetime
import html.parser as htmlparser
parser = htmlparser.HTMLParser()
# Mongo connection and Database initialization
myClient = pymongo.MongoClient('mongodb://localhost:27017/')
myDB = myClient['SST']
myCOL = myDB['SSTTemperature']

# Retreave and iterate through the recived document to get all the temperature data
recivedDocument = myCOL.find_one()
temperatureList = recivedDocument['StoragesList'][0]['TemperaturesList']
temperatureListLength = len(temperatureList)

# Save all the Temperature and date and time data in two separated arrays so that i can use them with chartJS
temperatureListData = []
timeListData = []
for everyTemperatureRead in range(temperatureListLength):
    temperatureListData.append(temperatureList[everyTemperatureRead]['Temperature']) # Now @tempListData ARRAY contains all the temperature data and ready to be use with chartJS
    timeListData.append(temperatureList[everyTemperatureRead]['Date']) # Now @timeListData ARRAY contains all the date and time data and ready to be use with chartJS

print(timeListData)

FLASK

from flask import Flask, render_template, request
import pymongo
import db

unitName = 'CBB-SST-R_1'

app = Flask (__name__)

@app.route('/')
def index():

    return render_template("index.html" , SQLdataTime = db.timeListData, SQLdataTemp =db.temperatureListData  )

    if __name__ == '__main__':
        app.run(debug=True)

CMD输出

['2019-08-16T11:26:52Z', '2019-08-16T11:31:52Z', '2019-08-16T11:36:52Z',....]

铬开发人员工具

['2019-08-16T11:26:52Z', '2019-08-16T11:31:52Z', '2019-08-16T11:36:52Z', '2019-08-16T11:41:52Z', '2019-08-16T11:46:52Z', .....]

额外的'是哪里来的?以及我的图表为空时如何解决此问题?

用于澄清我的问题的图片

Image shows the output of my application

python mongodb flask chart.js
1个回答
0
投票

出于安全原因,我找到了解决方案,Flask正在转义HTML,所以我必须通过在HTML文件中使用(| safe)过滤器来禁用它

例如:

{{ variableName | safe }}
© www.soinside.com 2019 - 2024. All rights reserved.