Page 1 sur 1

Comment diviser une valeur recue ?

Posté : 24 juin 2022, 19:41
par mykerinos1
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>

Re: Comment diviser une valeur recue ?

Posté : 11 janv. 2024, 02:25
par Masisud
Avez-vous déjà trouvé un moyen ?

shell shockers

Re: Comment diviser une valeur recue ?

Posté : 13 janv. 2024, 14:59
par dickheadnifty
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;

Re: Comment diviser une valeur recue ?

Posté : 16 janv. 2024, 05:31
par damiarobber
J'ai essayé mais ça n'a pas marché, y a-t-il un autre moyen ? space bar clicker

Re: Comment diviser une valeur recue ?

Posté : 23 janv. 2024, 09:29
par acquireblock
Masisud a écrit :
11 janv. 2024, 02:25
Avez-vous déjà trouvé un moyen ?survivor io

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?