Problem with showing the correct data on a line chart

33 views
Skip to first unread message

Gianni Declercq

unread,
Dec 25, 2016, 4:13:52 PM12/25/16
to Google Visualization API
Hello,

What I'm trying to create is a chart with multiple lines. I have for example 2 Raspberry Pi's which temperature data gets feed to the database. Each RPI has a unique ID which I call UID. 

I'm trying to loop over my query as you can see in my code so that I can create a seperate line for each RPI. But I'm having problems putting the temperature data from the database in an array. When for example the data when converted to json should be 

{"cols":[{"label":"datetime","type":"datetime"},{"label":"RPI1","type":"number"},{"label":"RPI2","type":"number"}],"rows":[{"c":[{"v":"Date(2016, 11, 25, 16, 29, 29)"},{"v":"20"},{"v":"12"}]},{"c":[{"v":"Date(2016, 11, 25, 16, 33, 22)"},{"v":"15"},{"v":"25"}]}]}


it outputs

{"cols":[{"label":"datetime","type":"datetime"},{"label":"RPI1","type":"number"},{"label":"RPI2","type":"number"}],"rows":[{"c":[{"v":"Date(2016, 11, 25, 16, 29, 29)"},{"v":"15"},{"v":"12"}]},{"c":[{"v":"Date(2016, 11, 25, 16, 33, 22)"},{"v":"15"},{"v":"25"}]}]}



I guess there is something going wrong when putting the temperature data in the DatabaseArray. But I can't seem to figure out how to do it the right way. (I'm a bit new when it comes to PHP)

My code is posted as a attachment, also an example of how it should approximatily look like in Excel. 



A picture of my database table:


graph.php
example.xlsx

Daniel LaLiberte

unread,
Dec 27, 2016, 11:48:59 AM12/27/16
to Google Visualization API
Hi Gianni,

Looks like your numbers needs to be non-string numeric values, not strings.  The Dates are a special case because to create a real date, you would have to use new Date(...) which is not allowed in JSON, so the Google Charts data can include "Date(..)" strings instead.

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/0cad39eb-bbe4-4bc5-a1d3-edef7b5e1913%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Gianni Declercq

unread,
Dec 27, 2016, 2:56:06 PM12/27/16
to Google Visualization API
Hello, Daniel,

Is it possible to give me an example how to do it the way I intended it to work? 

I really like to understand what I need to change as it would be a good exercise for me.

Op dinsdag 27 december 2016 17:48:59 UTC+1 schreef Daniel LaLiberte:
Hi Gianni,

Looks like your numbers needs to be non-string numeric values, not strings.  The Dates are a special case because to create a real date, you would have to use new Date(...) which is not allowed in JSON, so the Google Charts data can include "Date(..)" strings instead.
On Sun, Dec 25, 2016 at 4:13 PM, Gianni Declercq <g.decl...@gmail.com> wrote:
Hello,

What I'm trying to create is a chart with multiple lines. I have for example 2 Raspberry Pi's which temperature data gets feed to the database. Each RPI has a unique ID which I call UID. 

I'm trying to loop over my query as you can see in my code so that I can create a seperate line for each RPI. But I'm having problems putting the temperature data from the database in an array. When for example the data when converted to json should be 

{"cols":[{"label":"datetime","type":"datetime"},{"label":"RPI1","type":"number"},{"label":"RPI2","type":"number"}],"rows":[{"c":[{"v":"Date(2016, 11, 25, 16, 29, 29)"},{"v":"20"},{"v":"12"}]},{"c":[{"v":"Date(2016, 11, 25, 16, 33, 22)"},{"v":"15"},{"v":"25"}]}]}


it outputs

{"cols":[{"label":"datetime","type":"datetime"},{"label":"RPI1","type":"number"},{"label":"RPI2","type":"number"}],"rows":[{"c":[{"v":"Date(2016, 11, 25, 16, 29, 29)"},{"v":"15"},{"v":"12"}]},{"c":[{"v":"Date(2016, 11, 25, 16, 33, 22)"},{"v":"15"},{"v":"25"}]}]}



I guess there is something going wrong when putting the temperature data in the DatabaseArray. But I can't seem to figure out how to do it the right way. (I'm a bit new when it comes to PHP)

My code is posted as a attachment, also an example of how it should approximatily look like in Excel. 



A picture of my database table:


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.



--

Daniel LaLiberte

unread,
Dec 27, 2016, 4:10:39 PM12/27/16
to Google Visualization API
There are some examples on this page of the documentation: https://developers.google.com/chart/interactive/docs/datatables_dataviews#javascriptliteral

But it sounds like your problem might be how to set up things via PHP.  For that, this page might help:  https://developers.google.com/chart/interactive/docs/php_example

On Tue, Dec 27, 2016 at 2:56 PM, Gianni Declercq <g.decl...@gmail.com> wrote:
Hello, Daniel,

Is it possible to give me an example how to do it the way I intended it to work? 

I really like to understand what I need to change as it would be a good exercise for me.

Op dinsdag 27 december 2016 17:48:59 UTC+1 schreef Daniel LaLiberte:
Hi Gianni,

Looks like your numbers needs to be non-string numeric values, not strings.  The Dates are a special case because to create a real date, you would have to use new Date(...) which is not allowed in JSON, so the Google Charts data can include "Date(..)" strings instead.
On Sun, Dec 25, 2016 at 4:13 PM, Gianni Declercq <g.decl...@gmail.com> wrote:
Hello,

What I'm trying to create is a chart with multiple lines. I have for example 2 Raspberry Pi's which temperature data gets feed to the database. Each RPI has a unique ID which I call UID. 

I'm trying to loop over my query as you can see in my code so that I can create a seperate line for each RPI. But I'm having problems putting the temperature data from the database in an array. When for example the data when converted to json should be 

{"cols":[{"label":"datetime","type":"datetime"},{"label":"RPI1","type":"number"},{"label":"RPI2","type":"number"}],"rows":[{"c":[{"v":"Date(2016, 11, 25, 16, 29, 29)"},{"v":"20"},{"v":"12"}]},{"c":[{"v":"Date(2016, 11, 25, 16, 33, 22)"},{"v":"15"},{"v":"25"}]}]}


it outputs

{"cols":[{"label":"datetime","type":"datetime"},{"label":"RPI1","type":"number"},{"label":"RPI2","type":"number"}],"rows":[{"c":[{"v":"Date(2016, 11, 25, 16, 29, 29)"},{"v":"15"},{"v":"12"}]},{"c":[{"v":"Date(2016, 11, 25, 16, 33, 22)"},{"v":"15"},{"v":"25"}]}]}



I guess there is something going wrong when putting the temperature data in the DatabaseArray. But I can't seem to figure out how to do it the right way. (I'm a bit new when it comes to PHP)

My code is posted as a attachment, also an example of how it should approximatily look like in Excel. 



A picture of my database table:


--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsubscr...@googlegroups.com.



--

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages