相对来说,我是Python世界的新手。我想知道如何使用Python生态系统实现以下要求: 1.简单交互式网页供用户选择日期范围。例如,订单数据的“天数”范围选择。2.基于天数选择的Oracle 11g DB的Ferch数据。3.将数据转换为条形图,并在Web应用程序上显示。
我在谷歌上搜索了一下,但没有找到任何完整的信息。在此之前,非常感谢您。谢谢,Yogesh
发布于 2017-09-03 10:08:21
有几种方法可用,包括使用python库、sqlalchemy
或pandas
。但是,对于我在这里描述的方法,需要安装以下Python库。
Extracting Fields Names of an HTML form - Python
Dynamically serving a matplotlib image to the web using python
让我们假设您已经读取了用户输入和存储在变量st_date
和end_date
中的两个日期。这是密码。
import cx_Oracle
import matplotlib.pyplot as plt
query = 'SELECT order_date, count(order_id) order_count
FROM orders WHERE order_date BETWEEN ' + st_date + ' AND ' + end_date +
' GROUP BY order_date '
order_date = []
order_count = []
#connect to database and execute query.
db = cx_Oracle.connect('user', 'password', 'localhost:1521/XE')
cursor = db.cursor()
cursor.execute(query)
#loop through the rows fetched and store the records as arrays.
for row in cursor:
order_date.append(row[0])
order_count.append(row[1])
#plot the bar chart
plt.bar(order_date,order_count)
https://stackoverflow.com/questions/46020899
复制相似问题