谷歌图表中未显示的确切值

时间:2013-08-06 21:03:20

标签: php mysql

我正在使用此代码从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

感谢。

1 个答案:

答案 0 :(得分:0)

您需要对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