Using this data the graph is here.
In this format we can collect sample data from SQLite or MySQL database and display the graph.
Full code is here. Different options are explained using the comment section.
from sqlalchemy import create_engine
my_conn = create_engine("sqlite:///G:\\My Drive\\testing\\my_db\\my_db.db")
#my_conn = create_engine("mysql+mysqldb://userid:pw@localhost/my_tutorial")
q="SELECT class,count(*) as no FROM student GROUP BY class"
my_cursor=my_conn.execute(q) # getting record set
my_result=my_cursor.fetchall() # create a list
my_classes = [row[0] for row in my_result] # class as list
my_Nos = [row[1] for row in my_result] # number of student in class as list
# print(my_classes,my_Nos) # for checking output
We will connect to above code and get the variables my_classes and my_Nos.
from student_data import my_classes,my_Nos
Using data sources for drawing Pie chart
pc.data=my_Nos
pc.labels=my_classes
Full code of our Main file using database data as source is here.