iT邦幫忙

0

<已解決>Google Chart x軸錯亂

請教各位,我使用google chart 語法,但x軸數值 0不是在起點, 也不是由小至大,比例也不正確,是否需要增加什麼參數嗎 ?
https://ithelp.ithome.com.tw/upload/images/20200709/20127121grnKKECQig.png

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <script type="text/javascript">
      google.charts.load('current', {'packages':['bar']});
      google.charts.setOnLoadCallback(drawChart);

      function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['工作中心', '機台異常工時'],
          <?php

				while($row = $result->fetch(PDO::FETCH_ASSOC))
				{
					
					//時間計算
					$ZZNOTIME = round((strtotime(substr($row['end_at'], 0, 17) . "00") - strtotime(substr($row['start_1'], 0, 17) . "00")) / (60), 2);
					//print_r($row);
					//echo "<br>";

					echo "['".$row['arbpl']."','".$ZZNOTIME."',],";
					//echo "<br>";

				}

			?>
        ]);

        var options = {
          chart: {
            title: '工時統計圖',
            subtitle: '每日',
          },
          bars: 'horizontal' // Required for Material Bar Charts.
        };

        var chart = new google.charts.Bar(document.getElementById('barchart_material'));

        chart.draw(data, google.charts.Bar.convertOptions(options));
      }
    </script>

已解決 :
echo "['".$row['arbpl']."','".$ZZNOTIME."',],";
改寫成
echo "['".$row['arbpl']."',$ZZNOTIME],";

https://ithelp.ithome.com.tw/upload/images/20200709/20127121hElRdASLwm.png

1 個回答

1
海綿寶寶
iT邦大神 1 級 ‧ 2020-07-09 09:34:52

可能是資料的原因
(你的資料這裡看不到)

最終產生的 javascript code
Google Bar Chart的範例做比較看看

我要發表回答

立即登入回答