我对Python世界相对较新。我想知道如何使用Python生态系统达到要求, 1.简单的交互式网页,供用户选择日期范围。 例如。订单数据的'天'范围选择。 2.根据天数范围选择从Oracle 11g DB发送数据。 3.将数据转换为条形图并在Web应用程序上显示相同内容。
我google了一下,但没有找到任何完整的信息。 提前谢谢了。 谢谢, Yogesh
答案 0 :(得分:2)
有几种方法可供选择,包括使用python库sqlalchemy
或pandas
。但是,对于我在此描述的方法,您需要安装以下Python库。
<强> matplotlib 强>
我不会解释从网页获取用户输入或将图表存储为图像并在网页上显示图表的方法。您可以谷歌或参考这些问题的各种方法: -
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)