首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用Python应用程序连接Oracle DB绘制图形

用Python应用程序连接Oracle DB绘制图形
EN

Stack Overflow用户
提问于 2017-09-03 06:31:38
回答 1查看 1.2K关注 0票数 1

相对来说,我是Python世界的新手。我想知道如何使用Python生态系统实现以下要求: 1.简单交互式网页供用户选择日期范围。例如,订单数据的“天数”范围选择。2.基于天数选择的Oracle 11g DB的Ferch数据。3.将数据转换为条形图,并在Web应用程序上显示。

我在谷歌上搜索了一下,但没有找到任何完整的信息。在此之前,非常感谢您。谢谢,Yogesh

EN

回答 1

Stack Overflow用户

发布于 2017-09-03 10:08:21

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

  • cx_Oracle
  • matplotlib 我将不会解释从网页获取用户输入的方法,也不会将情节存储为图像并显示在网页上。你可以用谷歌或参考这些问题的各种方法:-

Extracting Fields Names of an HTML form - Python

Dynamically serving a matplotlib image to the web using python

让我们假设您已经读取了用户输入和存储在变量st_dateend_date中的两个日期。这是密码。

代码语言:javascript
运行
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46020899

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档