Pour toutes les discussions javascript, jQuery et autres frameworks
-
mykerinos1
- Messages : 12
- Enregistré le : 25 mai 2022, 07:57
Message
par mykerinos1 » 24 juin 2022, 19:41
Bonjour, je recois une donnee meteo que je souhaiterai diviser par 10 ".$row['Vents']." mais je n'ai pas trouvé comment faire . pouvez vous m aider ? j'ai essayé de diviser le row mais ca ne fonctionne pas
Merci
Code : Tout sélectionner
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(graph24h);
function graph24h() {
var data = google.visualization.arrayToDataTable([
['Date', 'Température', 'Vent Moyen', 'Humidité'],
<?php
$chartQuery = "SELECT * FROM ZiMeteo ORDER BY ID DESC LIMIT 144";
$chartQueryRecords = mysqli_query($connect, $chartQuery);
while ($row = mysqli_fetch_assoc($chartQueryRecords)) {
echo "['".$row['Date']."',".$row['TmpExt'].",".$row['Vents'].",".$row['HumExt']."],";
}
?>
]);
var options = {
title: 'Evolution sur 24 h',
titleColor: 'white',
backgroundColor: 'transparent',
color: ['white'],
hAxis: { direction: -1,
format:'MMM d, y',
textStyle: {
color:'white'
},
},
vAxis: {
textStyle: {
color:'white',
}},
chartArea: {left : 100,
width: 1000},
legend: { position: 'center',
textStyle: {
color: 'white'},
}
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
-
dickheadnifty
- Messages : 1
- Enregistré le : 13 janv. 2024, 14:57
Message
par dickheadnifty » 13 janv. 2024, 14:59
It looks like you want to divide the 'Vents' (wind) data by 10 in your PHP code before using it in the JavaScript part where you generate the chart. Here's how you can modify your PHP loop to achieve that:
<?php
$chartQuery = "SELECT * FROM ZiMeteo ORDER BY ID DESC LIMIT 144";
$chartQueryRecords = mysqli_query($connect, $chartQuery);
while ($row = mysqli_fetch_assoc($chartQueryRecords)) {
// Divide the 'Vents' (wind) data by 10
$dividedWind = $row['Vents'] / 10;
echo "['".$row['Date']."',".$row['TmpExt'].",".$dividedWind.",".$row['HumExt']."],";
}
?>
In the modified code, I introduced a new variable $dividedWind which represents the wind data divided by 10. I used this variable in the JavaScript part of your code.
This change assumes that $row['Vents'] contains numeric data. If it's stored as a string, you may need to convert it to a numeric type before performing the division. For example:
$dividedWind = floatval($row['Vents']) / 10;
-
acquireblock
- Messages : 1
- Enregistré le : 23 janv. 2024, 09:21
Message
par acquireblock » 23 janv. 2024, 09:29
In the PHP code, you should divide the 'Vents' (wind) data by 10. Then, in the JavaScript portion, you may use it to generate the chart, correct?
-
jenniferlopez1868
- Messages : 1
- Enregistré le : 20 févr. 2024, 03:23
Message
par jenniferlopez1868 » 08 avr. 2024, 10:52
Value added is the wealth created by an organization. The calculation of this additional value varies depending on the type of organization.
Slope Game
-
clintonhenry
- Messages : 2
- Enregistré le : 26 juin 2025, 11:07
Message
par clintonhenry » 19 janv. 2026, 08:13
Pour diviser la valeur de $row['Vents'] par 10, modifiez votre code comme suit :
stickman hook
echo "['".$row['Date']."',".$row['TmpExt'].",".$row['Vents']/10.",".$row['HumExt']."],";
Cela fonctionnera pour afficher la valeur divisée dans le graphique.
-
TaraBylba
- Messages : 1
- Enregistré le : Aujourd’hui, 10:32
Message
par TaraBylba » Aujourd’hui, 10:34
mykerinos1 a écrit : ↑24 juin 2022, 19:41
Bonjour, je recois une donnee meteo que je souhaiterai diviser par 10 ".$row['Vents']." mais je n'ai pas trouvé comment faire . pouvez vous m aider ? j'ai essayé de diviser le row mais ca ne fonctionne pas
Merci
Code : Tout sélectionner
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(graph24h);
function graph24h() {
var data = google.visualization.arrayToDataTable([
['Date', 'Température', 'Vent Moyen', 'Humidité'],
<?php
$chartQuery = "SELECT * FROM ZiMeteo ORDER BY ID DESC LIMIT 144";
$chartQueryRecords = mysqli_query($connect, $chartQuery);
while ($row = mysqli_fetch_assoc($chartQueryRecords)) {
echo "['".$row['Date']."',".$row['TmpExt'].",".$row['Vents'].",".$row['HumExt']."],";
}
?>
]);
var options = {
title: 'Evolution sur 24 h',
titleColor: 'white',
backgroundColor: 'transparent',
color: ['white'],
hAxis: { direction: -1,
format:'MMM d, y',
textStyle: {
color:'white'
},
},
vAxis: {
textStyle: {
color:'white',
}},
chartArea: {left : 100,
width: 1000},
legend: { position: 'center',
textStyle: {
color: 'white'},
}
};
var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
Souvent, le souci vient du fait que la valeur récupérée n’est pas interprétée comme un nombre (par exemple si elle est stockée comme chaîne de caractères). Tu peux essayer de la convertir avant de faire la division, par exemple en forçant le type :
$vent = (float)$row['Vents'] / 10;
Ça permet d’éviter les erreurs et d’avoir un résultat correct. Vérifie aussi que la valeur n’est pas vide ou mal formatée.
Quand je bloque sur ce genre de petits détails, j’aime bien garder sous la main quelques ressources ou liens utiles pour comparer différentes approches, comme
el-annuaire-gratuit.com/melbet-inscription-afrique
Bon courage, normalement avec la conversion ça devrait fonctionner
