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

您需要添加 pieSliceText 参数,它采用以下值 'percentage'、'value'、'label' 和 'none'

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 回答