Comment diviser une valeur recue ?

Pour toutes les discussions javascript, jQuery et autres frameworks
Répondre
mykerinos1
Messages : 12
Enregistré le : 25 mai 2022, 07:57

Comment diviser une valeur recue ?

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>

Masisud
Messages : 1
Enregistré le : 11 janv. 2024, 02:24

Re: Comment diviser une valeur recue ?

Message par Masisud » 11 janv. 2024, 02:25

Avez-vous déjà trouvé un moyen ?

shell shockers

dickheadnifty
Messages : 1
Enregistré le : 13 janv. 2024, 14:57

Re: Comment diviser une valeur recue ?

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;

damiarobber
Messages : 2
Enregistré le : 15 janv. 2024, 08:34

Re: Comment diviser une valeur recue ?

Message par damiarobber » 16 janv. 2024, 05:31

J'ai essayé mais ça n'a pas marché, y a-t-il un autre moyen ? space bar clicker

acquireblock
Messages : 1
Enregistré le : 23 janv. 2024, 09:21

Re: Comment diviser une valeur recue ?

Message par acquireblock » 23 janv. 2024, 09:29

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?

Répondre