How to plot Barchart using database queries
-
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)
-
@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.