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)
有几种可用的方法包括使用python库}。但是,对于我在这里描述的方法,您需要安装以下Python库。在
sqlalchemy
或{matplotlib
我不会解释从网页获取用户输入的方法,也不会将绘图存储为图像并在网页上显示绘图。您可以通过谷歌或参考以下问题找到各种方法:-
Extracting Fields Names of an HTML form - Python
Dynamically serving a matplotlib image to the web using python
假设您已经阅读了用户输入和存储在变量
st_date
和end_date
中的两个日期。这是密码。在相关问题 更多 >
编程相关推荐