第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Google Charts 餅圖顯示其他 100%

Google Charts 餅圖顯示其他 100%

PHP
慕俠2389804 2023-09-22 16:49:23
<html>  <head>    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>    <script type="text/javascript">      google.charts.load('current', {'packages':['corechart']});      google.charts.setOnLoadCallback(drawChart);      function drawChart() {        var data = google.visualization.arrayToDataTable([          ['Task', 'Hours per Day'],          <?php            $query = "SELECT name, score FROM `Users` order by score desc limit 5";            $result = mysqli_query($conn, $query);            if ($result->num_rows > 0) {              while($row = mysqli_fetch_array($result))              {                echo "['".$row['name']."', '".$row['score']."'],";              }             }          ?>        ]);        var options = {          title: 'My Daily Activities'        };        var chart = new google.visualization.PieChart(document.getElementById('piechart'));        chart.draw(data, options);      }    </script>  </head>  <body>    <div id="piechart" style="width: 900px; height: 500px;"></div>  </body></html>我的代碼有什么問(wèn)題嗎?我讀到我的值存儲(chǔ)為字符串,以便圖表顯示 100% 其他。我該如何讓它發(fā)揮作用?我嘗試使用(int)$varPHP 函數(shù),但這還不能使它工作..              while($row = mysqli_fetch_array($result))              {                $score = $row['score'];                $int = (int)$score;                echo "['".$row['name']."', '".$row['score']."'],";              }             }
查看完整描述

1 回答

?
慕的地6264312

TA貢獻(xiàn)1817條經(jīng)驗(yàn) 獲得超6個(gè)贊

不要自己生成json。json_encode 始終使用:


<?php

$query = "SELECT name, score FROM `Users` order by score desc limit 5";

$result = mysqli_query($conn, $query);

$chartData = [

    ['Task', 'Hours per Day'],

];

if ($result->num_rows > 0) {

    while($row = mysqli_fetch_array($result))

    {

        $chartData[] = [$row['name'], $row['score']];

    } 

}?>

<script type="text/javascript">

  google.charts.load('current', {'packages':['corechart']});

  google.charts.setOnLoadCallback(drawChart);


  function drawChart() {


    var data = google.visualization.arrayToDataTable(<?php echo json_encode($chartData)?>);


    var options = {

      title: 'My Daily Activities'

    };


    var chart = new google.visualization.PieChart(document.getElementById('piechart'));


    chart.draw(data, options);

  }

</script>


查看完整回答
反對(duì) 回復(fù) 2023-09-22
  • 1 回答
  • 0 關(guān)注
  • 100 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)