Php/javascript problem with array

Hello,

Im trying to make a columnchart with data (temp/time) i recieved with php request. I succeeded to get all the data i wanted in a table and also in an array.

Code:

echo "<table>";
for($i=0;$i<40;$i++)
{
echo "<tr>
<td id=\"datatime[$i]\">{$data->list[$i]->dt_txt}</td>
<td id=\"datatemp[$i]\">{$data->list[$i]->main->temp}</td>
</tr>";
}

Now i want to use this data to draw a chart with javascript.

code:

google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart()
{
for (i=0; i<40;i++)
{

var time =[document.getElementById("datatime["+i+"]").textContent];
console.log(time);
var temp =[document.getElementById("datatemp["+i+"]").textContent];
console.log(temp);
var data = google.visualization.arrayToDataTable([
['date', 'temp'],
[time <i>, parseFloat(temp <i>)]
]);
console.log(time <i>)
var options = {'title':'temperatuur per tijdstip', 'width':2000, 'height':700};

var chart = new google.visualization.ColumnChart(document.getElementById('barchart'));
chart.draw(data, options);
}
}

The problem i have is that i can’t figure out how to get all the data times/temps in the chat. In my code i also console.logged time/temp to see what it does. I figured out all temps/times showed up in console but all in the array index 0. Anyone who can help me get all the times/temps in my chart?

Thx in advance

Welcome, anthony.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums