arrayToDataTable expects an array. Use

var data = new google.visualization.DataTable();

if you want to specify/customize columns, or just

var data = google.visualization.arrayToDataTable( JSON.parse(<?= $json ?>));

(Not tested, but this should get you headed in the right direction ;)


On Mon, Mar 25, 2019 at 9:59 AM Tammi <[email protected]> wrote:

> I am trying to get a returned JSON array to display in a google table
> chart. Can someone help me with this. So far no luck.
>
> Here is a sample of the json that is returned. That is what is echo'd out
> to browser.
>
>
>           [{
>    "ts": 1552903183141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903173141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903163141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903153141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903143141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903133141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903123141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903113141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }, {
>  "ts": 1552903103141,
>    "sk": "testing123",
>     "val": 0,
>       "qual": 0,
>      "tg": "hb"
> }]
>
>
>
> this is the graph.
>
>
>
> <html>
>   <head>
>     <script type="text/javascript" src="
> https://www.gstatic.com/charts/loader.js";></script>
>     <script type="text/javascript">
>       google.charts.load('current', {'packages':['table']});
>       google.charts.setOnLoadCallback(drawTable);
>       function drawTable() {
>         var data = google.visualization.arrayToDataTable([
>         data.addColumn('string', 'sk');
>         data.addColumn('string', 'ts');
>         data.addColumn('string', 'val');
> data.addColumn('string', 'qual');
> data.addColumn('string', 'tg');
>         data.addRow([
>
>     ['<?php
> for ($i = 0; $i < count($json); $i++) {
> echo $json[$i]['sk'];
> echo $json[$i]['ts'];
> echo $json[$i]['val'];
> echo $json[$i]['qual'];
> echo $json[$i]['tg'];
> }
>   ?>']
>
>         ]);
>
>         var table = new
> google.visualization.Table(document.getElementById('table_div'));
>
>         table.draw(data, {showRowNumber: true, width: '50%', height:
> '50%'});
>       }
>     </script>
>   </head>
>   <body>
>   </br>
>     <div id="table_div"></div>
>   </body>
> </html>
>
>
> thanks for any help
>
> --
> 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 [email protected].
> To post to this group, send email to
> [email protected].
> 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/ba547473-4b4e-423b-8fcf-0d285c3b0caf%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/ba547473-4b4e-423b-8fcf-0d285c3b0caf%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
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/CAAo1oYXAfXKHRvab6XNNr0g7hveQ4g4eQnAzD31y4d2Twun_6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to