lundi 9 mars 2015

mysql data to chart

I have these tables for recording attendances of each classes on different dates



tbl_attendances:
attendance_id (A.I.) | class_id | class_date | person_id

tbl_classes:
class_id (A.I.) | class_name | etc.

tbl_persons:
person_id (A.I.) | last_name | etc.


when I add a new attendance, I use this



INSERT INTO tbl_class_attendances(class_id, class_date, person_id)
VALUES(1, '2015-03-09', 1)


recently i have been asked to convert these data into line graph like this



500
400
300
200
100
0
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec


where the Series would be the different classes and they have the options to select which Year should be displayed


I have been studying the basics of using the .net chart and have found out that to use a chart, I need to plot the points individually


for example



Chart1.Series("English").Points.AddXY("January", 138)
Chart1.Series("English").Points.AddXY("February", 239)

Chart1.Series("Science").Points.AddXY("January", 245)
Chart1.Series("Science").Points.AddXY("February", 189)


to get the attendances of a month by each classes, I use this



SELECT COUNT(attendance_id) FROM tbl_class_attendances
GROUP BY class_id, YEAR(class_date), MONTH(class_date)


So, does it mean that i have to use the COUNT() function multiple times? one for each month? and one for each each classes?


what is the best way to get the COUNT() of each months by using just a single query? (and also the fastest and most efficient way) . If is not possible on a single query, It's ok


Right now, I have no experience in using any charts. It's my first time. If you have better ideas on how to achieve my goal, please let me know. thanks


Aucun commentaire:

Enregistrer un commentaire