I'm using MySQL+PHP+Morris.js to generate some line graphs. I want the result graph to look like this:
morris.js line graph
I understand the data should look like below for morris.js to generate the graph:
{"period": "2014 Q3", "A": 75, "B": 77, "C": 79},
{"period": "2014 Q2", "A": 85, "B": 87, "C": 89},
{"period": "2014 Q1", "A": 93, "B": 95, "C": 97}
However I'm having trouble getting to this format using PHP+MySQL.
My database structure looks like this.
table1: numbers
ID | name | time | number
------+------+------+---
1 | A | 1 | 75
2 | A | 2 | 77
3 | A | 3 | 79
4 | B | 1 | 85
5 | B | 2 | 87
6 | B | 3 | 89
7 | C | 1 | 93
8 | C | 2 | 95
9 | C | 3 | 97
table2: times
ID | time
----+------
1 | 2014 Q1
2 | 2014 Q2
3 | 2014 Q3
Is there a way to get the format morris.js wanted? Or is there any other way to generate the graph using some other kind of format?
Hopefully I won't have to change the structure of my database :(
Thanks much!
Aucun commentaire:
Enregistrer un commentaire