第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

pyqt QChart 沒有顯示任何結(jié)果

pyqt QChart 沒有顯示任何結(jié)果

白豬掌柜的 2023-10-26 10:50:00
我正在使用 pyqt GUI 應(yīng)用程序在 postgres 數(shù)據(jù)庫的圖表中顯示一些結(jié)果,但它不起作用這是我使用的代碼這就是我創(chuàng)建表格的方式create_table_transaction = ''' CREATE TABLE IF NOT EXISTS transactions (            id SERIAL PRIMARY KEY  UNIQUE NOT NULL,            montant DECIMAL(100,2),             medecin VARCHAR,            date_d DATE,             time_d TIME,            users_id INTEGER,             FOREIGN KEY(users_id) REFERENCES users(id)) '''這是在 Qchart 小部件中繪制圖表的功能from PyQt5 import *from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupportfrom PyQt5.QtCore import *from PyQt5.QtWidgets import *from PyQt5.QtGui import *from PyQt5.QtCore import Qtfrom PyQt5.QtSql import *from PyQt5.QtPrintSupport import QPrintDialog, QPrinter, QPrintPreviewDialogimport sys, sqlite3import psycopg2import datetimefrom datetime import timedeltafrom PyQt5.QtCore import QDateimport sysfrom PyQt5.QtChart import QChart, QLineSeriesfrom PyQt5.QtChart import *from PyQt5.uic import loadUiTypefrom admin import Ui_MainWindow as uiclass MainApp(QMainWindow, ui):    def __init__(self):        QMainWindow.__init__(self)        self.setupUi(self)        self.Handel_Buttons()    def Handel_Buttons(self):        self.pushButton_113.clicked.connect(self.draw_chart01)    def draw_chart01(self): #pushButton_113                    self.connection = psycopg2.connect(user="postgres",                                            password="password",                                            host="localhost",                                            database="database")            self.cur = self.connection.cursor()            date = str(self.dateEdit_19.text())             self.cur.execute( '''SELECT medecin, montant FROM transactions WHERE date_d = %s ''',(date,))            rows = self.cur.fetchall()            rightseries = QPieSeries()            for entry in rows:                print(entry)                rightseries.append(entry[0], entry[1])
查看完整描述

1 回答

?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊

這樣做self.graphicsView = QChartView(rightchart)不會(huì)替換 QChartView,但“graphicsView”變量現(xiàn)在指示新的 QChartView,因此您會(huì)收到錯(cuò)誤。解決辦法是在現(xiàn)有的QChartView中設(shè)置QChart:


import sys


from PyQt5.QtWidgets import QApplication, QMainWindow

from PyQt5.QtChart import QPieSeries, QChart


import psycopg2


from admin import Ui_MainWindow as ui



class MainApp(QMainWindow, ui):

    def __init__(self):

        QMainWindow.__init__(self)

        self.setupUi(self)

        self.Handel_Buttons()


    def Handel_Buttons(self):

        self.pushButton_113.clicked.connect(self.draw_chart01)


    def draw_chart01(self):


        connection = psycopg2.connect(

            user="postgres", password="password", host="localhost", database="database"

        )

        cur = connection.cursor()


        date = str(self.dateEdit_19.text())


        cur.execute(

            """SELECT medecin, montant FROM transactions WHERE date_d = %s """, (date,)

        )


        rows = cur.fetchall()

        rightseries = QPieSeries()


        for medecin, montant in rows:

            rightseries.append(medecin, montant)


        rightchart = QChart()

        rightchart.addSeries(rightseries)

        rightchart.setTitle("title")

        rightchart.setAnimationOptions(QChart.SeriesAnimations)


        self.graphicsView.setChart(rightchart)



if __name__ == "__main__":


    app = QApplication(sys.argv)

    app.setStyle("Fusion")

    window = MainApp()

    window.show()

    sys.exit(app.exec_())


查看完整回答
反對 回復(fù) 2023-10-26
  • 1 回答
  • 0 關(guān)注
  • 245 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號