0

このコードを使用して mysql からデータを呼び出し、円グラフとして表示しています。しかし、チャートは列からの正確な値を表示していませんが、パーセンテージで表示しています。

正確な値を表示したい。

これは私のコードです

<?php
$con=mysql_connect("localhost","pramir_feedback","feedback") or die("Failed to connect with database!!!!");
mysql_select_db("pramir_feedback", $con); 
$sth = mysql_query("SELECT * FROM average");

$rows = array();
$flag = true;
$table = array();
$table['cols'] = array(

    array('label' => 'data', 'type' => 'string'),
    array('label' => 'average', 'type' => 'number')

);

$rows = array();
while($r = mysql_fetch_assoc($sth)) {
    $temp = array();
    $temp[] = array('v' => (string) $r['data']); 

    $temp[] = array('v' => (int) $r['average']); 
    $rows[] = array('c' => $temp);
}

$table['rows'] = $rows;
$jsonTable = json_encode($table);

?>

<html>
  <head>
    <!--Load the Ajax API-->
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script type="text/javascript">

    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);

    function drawChart() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(<?=$jsonTable?>);
      var options = {
           title: 'Average Data',
          is3D: 'true',
          width: 800,
          height: 600
        };
      // Instantiate and draw our chart, passing in some options.
      // Do not forget to check your div ID
      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
    </script>
  </head>

  <body>
    <!--this is the div that will hold the pie chart-->
    <div id="chart_div">fgfgfgfhiefkefejkfwefhfwjkefewfwf</div>
  </body>
</html>

ここでチャートを見ることができますhttp://innovatrix.co.in/feedback_priyajit/graph.php

ありがとう。

4

1 に答える 1

0

次の値「percentage」、「value」、「label」、および「none」を取る pieSliceText パラメーターを広告する必要があります。

var options = {
       title: 'Average Data',
      is3D: 'true',
      width: 800,
      height: 600,
      pieSliceText : 'value'};

詳細については、こちらをクリックして ください https://developers.google.com/chart/interactive/docs/gallery/piechart#Configuration_Options

于 2013-08-06T21:40:21.053 に答える