Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to plot Barchart using database queries
Qt 6.11 is out! See what's new in the release blog

How to plot Barchart using database queries

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 563 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by LT-K101
    #1

    I want to plot a piechart using three values from sql statements(first_value, second_value and third_value) and display the chart on a QverticalLayout (the layoutName is verticalLayout) which i design with QT designer, implementing this using the values from the sql queries seem confusing. Please I need assistance, below is the code .Thank you.

    from PyQt5.QtChart import QChart, QChartView, QBarSet, QPercentBarSeries, QBarCategoryAxis ,QPieSeries,QBarSeries,QValueAxis,QAbstractBarSeries
    import sqlite3
    import sys, os
    
    
    series = QPieSeries
    
    series.append("first_total",first_value)
    series.append("second_total",second_value)
    series.append("third_total",third_value)
    
    
    chart = QChart()
    chart.addSeries(series)
    chart.setAnimationOptions(QChart.SeriesAnimations)
    chart.setTitle("My Total")
    
    
    chartview = QChartView(chart)
    
    
    vbox = QVBoxLayout()
    vbox.verticalLayout(chartview)
    
    
    JonBJ 1 Reply Last reply
    0
    • L LT-K101

      I want to plot a piechart using three values from sql statements(first_value, second_value and third_value) and display the chart on a QverticalLayout (the layoutName is verticalLayout) which i design with QT designer, implementing this using the values from the sql queries seem confusing. Please I need assistance, below is the code .Thank you.

      from PyQt5.QtChart import QChart, QChartView, QBarSet, QPercentBarSeries, QBarCategoryAxis ,QPieSeries,QBarSeries,QValueAxis,QAbstractBarSeries
      import sqlite3
      import sys, os
      
      
      series = QPieSeries
      
      series.append("first_total",first_value)
      series.append("second_total",second_value)
      series.append("third_total",third_value)
      
      
      chart = QChart()
      chart.addSeries(series)
      chart.setAnimationOptions(QChart.SeriesAnimations)
      chart.setTitle("My Total")
      
      
      chartview = QChartView(chart)
      
      
      vbox = QVBoxLayout()
      vbox.verticalLayout(chartview)
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @LT-K101 said in How to plot Barchart using database queries:

      implementing this using the values from the sql queries seem confusing.

      What does this mean? What are you actually asking us?? The fact that you get data from a database has no connection to code for adding bars on a chart. Your series appending looks OK, only you know what is in first_value etc. and how you got it from the database. I don't see what you think someone else can say.

      Break your problem into two:

      • Get the bar/pie chart right by testing with sample hard-coded values, no database.
      • Get your data from database queries, printing out the results, no charts.

      Then just connect the two bits of code.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved