Make graph with google visualization with two arrays

1 answer

Hi I want to make a graph from data in a database using google visualization here is the code i am using:

<?php $connect = mysqli_connect("db_host", "db_name", "db_pass", "db_table");      if(!$connect ) {     die('Connection failed: ' . mysqli_error()); } echo 'Connected successfully';    $tempsql="SELECT `temperature` FROM `apidata`"; $resulttemp = $connect->query($tempsql); $temp=array(); foreach ($resulttemp as $rowtemp){     $temp[]=$rowtemp; } $resulttemp->close();  $idsql="SELECT `id` FROM `apidata`"; $resultid = $connect->query($idsql); $id=array(); foreach ($resultid as $rowid){     $id[]=$rowid; } $resultid->close();  $js_arrayTemp = json_encode($temp); //echo "var javascript_array = ". $js_array . ";\n"; $js_arrayId=json_encode($id); //echo "var javascript_array = ". $js_array2 . ";\n";  mysqli_close($connect); ?> <script type="text/javascript" src=""></script> <script type="text/javascript">  function drawVisualization() {   // Create and populate the data table.   var Temp = <?php echo $js_arrayTemp;?>;   var id = <?php echo $js_arrayId;?>;    var data = new google.visualization.DataTable();   data.addColumn('string', 'id');   data.addColumn('number', 'temp');    for(i = 0; i < id.length; i++)     data.addRow([id[i], Temp[i]]);    // Create and draw the visualization.   new google.visualization.LineChart(document.getElementById('visualization')).     draw(data, {}); }  </script>  

When i look at my website there is no graph. But in the debugger i can see the data Pictue of debugger Picture og debugger 2 Hope someone can see my problem.

All answers to this question, which has the identifier 61208065

The best answer:

can't use an object as a column value, here...

data.addRow([id[i], Temp[i]]); 

where Temp[i] = {"temperature": "6"}

instead, get the value of the object...

data.addRow([parseInt(id[i].id), parseFloat(Temp[i].temperature)]); 

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type is referenced as an interface from”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data