JSON.parse expects a string, so add quotes:
JSON.parse('<?php echo $json ?>')

On Tue, Mar 26, 2019, 7:14 AM Tammi <deathspera...@gmail.com> wrote:

> can anyone else help ? give me an example of how to display this data from
> the json array variable?
>
> On Monday, March 25, 2019 at 11:21:04 AM UTC-4, Tammi wrote:
>>
>> Thank you. I tried and I still get this error
>>
>> Uncaught SyntaxError: Unexpected token <
>>
>>
>>
>>
>> <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( JSON.parse(<?=
>> $json ?>));
>>
>>         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>
>>
>>
>>
>> On Monday, March 25, 2019 at 11:11:35 AM UTC-4, Jerry O'Brien wrote:
>>>
>>> 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 <deaths...@gmail.com> 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 google-visualization-api+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to google-visua...@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/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 google-visualization-api+unsubscr...@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/210be0fd-55f7-4582-a7dd-05bff5652c83%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/210be0fd-55f7-4582-a7dd-05bff5652c83%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 google-visualization-api+unsubscr...@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/CAAo1oYXSu17idQGeJY4gicESXmJn2gES%2By7xwU6fwJrPvaH%3Dmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to