j'affiche des graphiques (googlechart) reposant sur une base mysql sur une page html.
j'utilise un picker date pour afficher le graphique selon un jour donné mais lorsque je sélectionne la page au départ, elle est vide tant que je n ai pas sélectionné une date.
j 'aimerai que , lorsque je selectionne la page de graphique temperature alors la courbe des dernieres 24 h s affiche.
merci a vous.
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(graphtemp);
function graphtemp() {
var data = google.visualization.arrayToDataTable([
['Date', 'Température '],
<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
if (isset($_POST['selectedatetemp'])) {
$timestamp = strtotime($_POST['selectedatetemp']);
$date = date('Y-m-d ', $timestamp);
$month = (int) date('n', $timestamp);
$year = (int) date('Y', $timestamp);
$chartQuery = "SELECT date_format(Date,'%d/%m/%Y %H:%i ') AS 'Update', TmpExt AS TmpExt_Max FROM ZiMeteo WHERE DATE(Date) = ('$date') ORDER BY ID DESC LIMIT 144 ";
}
else {
$chartQuery = "SELECT date_format(Date,'%d/%m/%Y %H:%i ') AS 'Update', TmpExt AS TmpExt_Max FROM ZiMeteo WHERE DATE(Date) = ('$date') ORDER BY ID DESC LIMIT 144 ";
}
$chartQueryRecords = mysqli_query($connect, $chartQuery);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
while ($row = mysqli_fetch_assoc($chartQueryRecords)) {
echo "['".$row['Update']."',".$row['TmpExt_Max']."],";
}
?>
]);
var options = {
explorer: {
axis: 'horizontal',
keepInBounds: true,
maxZoomIn: 4.0
},
series: {
0: { color: '#D80010' },
1: { color: 'blue' },
},
backgroundColor: 'transparent',
color: ['white'],
lineWidth: 4,
hAxis: { direction: -1,
format:'MMM d, y',
textStyle: {
color:'white'
},
},
vAxis: {
textStyle: {
color:'red',
},
explorer: {
axis: 'horizontal',
keepInBounds: true,
maxZoomIn: 4.0,
},
},
chartArea: {left : 100,
width: 1130},
legend: { position: 'bottom',
textStyle: {
color: 'white'},
}
};
var chart = new google.visualization.AreaChart(document.getElementById('temp_chart'));
chart.draw(data, options);
}
</script>
<form action="temperature.php" method="POST" name="formulaire">
<input type="date" name="selectedatetemp" defaultDate= "now">
<input type="submit" value="Go">
</form>