Have a look at this fiddle using your sample data:
https://jsfiddle.net/obrienje/gq5j6L0u/15/

On Wed, Mar 27, 2019 at 8:35 AM Tammi <deathspera...@gmail.com> wrote:

> yes here you go.
>
>
> <?php
> echo "<h3>testing</h3>";
>
> //initiate the curl request for token
> $curl = curl_init();
> //create the request array for token
> curl_setopt_array($curl, array(
>   CURLOPT_URL => "blablabla/token?grant_type=password",
>   CURLOPT_RETURNTRANSFER => true,
>   CURLOPT_ENCODING => "",
>   CURLOPT_MAXREDIRS => 10,
>   CURLOPT_TIMEOUT => 30,
>   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
>   CURLOPT_CUSTOMREQUEST => "POST",
>   CURLOPT_HTTPHEADER => array(
>     "authorization: Basic 123"
>   ),
> ));
>
> $response = curl_exec($curl);
> $err = curl_error($curl);
> curl_close($curl);
> if ($err) {
>   echo "cURL Error #:" . $err;
> } else {
>   $json = json_decode($response, true);
>   $token = $json['token'];
> }
>
> ?>
>
> </br>
> <form action=# method="post">
> Source Key: <input type="text" name="skk">
> </br></br>
> Date Start: <input type="date" name="dtstart"> (not in use yet)
> </br>
> Date End: <input type="date" name="dtend"> (not in use yet)
> </br>
> <input type="submit">
> </form>
>
>
> <?php
>
>      if(isset($_POST['submit']))
> {
>         $test = $_POST['skk'];//assigning your input value
>
>         if(isset($test))
>         {
>             $fr=fopen("php://stdin","r");   // open our file pointer to
> read from stdin
>             $input = fgets($fr,128);        // read a maximum of 128
> characters
>             $input = rtrim($input);         // trim any trailing spaces.
>             fclose ($fr);                   // close the file handle
>             $result =  $input;              // return the text entered
>         }
>     }
> ?>
>
>
> You have entered : <?php echo $_POST["skk"];
> echo "</br></br>";
>
>
>
>
> //set my base url for the api
> $myurl = "https://blablabla/admin?skk=";;
> //set my limit
> $limit = "&limit=10";
> //create my concatenated url
> $endurl = $myurl.$_POST["skk"].$limit;
>
> //send the request
> $curl = curl_init();
> curl_setopt_array($curl, array(
>   CURLOPT_URL => $endurl,
>   CURLOPT_RETURNTRANSFER => true,
>   CURLOPT_ENCODING => "",
>   CURLOPT_MAXREDIRS => 10,
>   CURLOPT_TIMEOUT => 30,
>   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
>   CURLOPT_CUSTOMREQUEST => "POST",
>   CURLOPT_HTTPHEADER => array(
>     "authorization: bearer $token"
>   ),
> ));
>
> $response = curl_exec($curl);
> $err = curl_error($curl);
> curl_close($curl);
> if ($err) {
>   echo "cURL Error #:" . $err;
> } else {
>   $json = json_encode($json);
>   //print_r($json);
> }
>
> //create some variables for data points
> $ts = $json[0]['ts'];
> $val = $json[0]['val'];
> $qual = $json[0]['qual'];
> $tag = $json[0]['tg'];
> $sk = $json[0]['sk'];
>
>
> //create a formatted date from timestamp for future use
> $formatdt = date("Y-m-d H:i:s", substr($dt, 0, 10));
> //whats my current date
> $cur_date = date("Y-m-d H:i:s");
> echo "</br>";
>
> //convert back to timestamps
> $date1Timestamp = strtotime($formatdt);
> $date2Timestamp = strtotime($cur_date);
>
> //Calculate the difference
> $difference = $date2Timestamp - $date1Timestamp;
> //echo $difference;
>
> //tellem whats wrong
> if ($difference<60)
> {
> echo "<h2>" . $skk . " is <font color=green>UP </font></h2>";
> }
> else
> {
> echo "<h2>" . $skk . " is <font color=red>DOWN </font></h2>";
> }
>
> echo "</br>";
>
>
> //remove brackets
> //$suba = substr($json_stringa, 1, -1);
> //echo $suba;
>
> ?>
>
>
> <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([
>
>
>
>         ]);
>
>         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 Wednesday, March 27, 2019 at 9:20:53 AM UTC-4, Jerry O'Brien wrote:
>>
>> Can you post a complete code example?
>>
>> On Wed, Mar 27, 2019 at 7:09 AM Tammi <deaths...@gmail.com> wrote:
>>
>>> Yes I have done that already. I send a curl request, when the response
>>> comes back I :
>>>
>>> $json = json_encode($json);
>>>
>>> I still get errors and the chart never loads.
>>>
>>>
>>>
>>> On Tuesday, March 26, 2019 at 8:28:24 PM UTC-4, Jerry O'Brien wrote:
>>>>
>>>> Have you serialized your PHP array to JSON in index.php?
>>>>
>>>> $json = json_encode($my_array);
>>>>
>>>> Or in your JS, you could say JSON.parse('<?php echo
>>>> json_encode($my_array)   ?>')
>>>>
>>>>
>>>> On Tue, Mar 26, 2019 at 8:19 AM Tammi <deaths...@gmail.com> wrote:
>>>>
>>>>> Thanks. Tried that I get this error.
>>>>>
>>>>> Array to string conversion in
>>>>> <b>C:\xampp\htdocs\dashboard\index.php</b> on line <b>151</b><br />
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> On Tuesday, March 26, 2019 at 9:09:47 AM UTC-4, Jerry O'Brien wrote:
>>>>>>
>>>>>> JSON.parse expects a string, so add quotes:
>>>>>> JSON.parse('<?php echo $json ?>')
>>>>>>
>>>>>> On Tue, Mar 26, 2019, 7:14 AM Tammi <deaths...@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-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/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-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/fd5a27cf-91a1-4d09-a25b-40f9d806892a%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/google-visualization-api/fd5a27cf-91a1-4d09-a25b-40f9d806892a%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-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/5e238d4b-b0fe-4df1-9c65-93017b65d3b3%40googlegroups.com
>>> <https://groups.google.com/d/msgid/google-visualization-api/5e238d4b-b0fe-4df1-9c65-93017b65d3b3%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/96bbc010-2b44-4498-b82e-d53e8e5eae48%40googlegroups.com
> <https://groups.google.com/d/msgid/google-visualization-api/96bbc010-2b44-4498-b82e-d53e8e5eae48%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/CAAo1oYW5MVPE80TrO_JYzj7j1zCw8qdk98N1zchaBkuftcsMHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to