通过连接到oracledb使用python web app绘制图形

2024-09-29 21:30:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我对Python世界比较陌生。我想知道如何使用Python生态系统实现低于要求的目标, 1简单的交互式网页,供用户选择日期范围。 E、 g.订单数据的“天数”范围选择。 2来自oracle11gdb的Ferch数据基于天范围选择。 三。将数据转换成条形图,并在Web应用程序中显示相同的数据。在

我在谷歌上搜索了一下,但没有找到完整的信息。 提前致谢。 谢谢, 瑜伽士


Tags: 数据用户订单web信息应用程序网页目标
1条回答
网友
1楼 · 发布于 2024-09-29 21:30:27

有几种可用的方法包括使用python库sqlalchemy或{}。但是,对于我在这里描述的方法,您需要安装以下Python库。在

  • cx甲骨文
  • matplotlib

    我不会解释从网页获取用户输入的方法,也不会将绘图存储为图像并在网页上显示绘图。您可以通过谷歌或参考以下问题找到各种方法:-

Extracting Fields Names of an HTML form - Python

Dynamically serving a matplotlib image to the web using python

假设您已经阅读了用户输入和存储在变量st_dateend_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)

相关问题 更多 >

    热门问题