显示数据时不显示趋势线

Trendline is not showing when displaying data

从 MySQL 查询数据时未显示趋势线。月份和结果都是整数格式。附件是图表图像,趋势线不起作用。可以帮我吗?

编码部分是这样的:

<?php
   include ('connection.php');
?>


<html>
   <head>
      <title>Google Charts Tutorial</title>
      <script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js">
      </script>
      <script type = "text/javascript" src = "https://www.google.com/jsapi">
      </script>
      <script type = "text/javascript">
         google.charts.load('current', {packages: ['corechart']});    
      </script>
   </head>

   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto">
      </div>
      <script language = "JavaScript">
       function drawChart() {
      var data = google.visualization.arrayToDataTable([
         ['Month', 'Performance %'],
         <?php
          $query = "SELECT month , result_ind FROM performance GROUP BY month";


          $exec = mysqli_query($db,$query);
          while($row = mysqli_fetch_assoc($exec)){


          echo "['".$row['month']."',".$row['result_ind']."],";
         }
        ?>
       ]);



            // Set chart options
            var options = {
               'title':'Month vs %',
               'width':550,
               'height':400,

                trendlines: {
                0: {
                type: 'exponential',
                color: 'green',
                visibleInLegend: true,
      }
    }  // Draw a trendline for data series 0.
            };


            // Instantiate and draw the chart.
            var chart = new google.visualization.ScatterChart(document.getElementById('container'));
            chart.draw(data, options);
         }
         google.charts.setOnLoadCallback(drawChart);
      </script>
   </body>
</html>

趋势线仅适用于连续轴(数字、日期等...)

不在离散轴上(字符串)

因此,您需要从 x 轴值中删除单引号,此处...

echo "[".$row['month'].",".$row['result_ind']."],";