Google图表:我无法标记我的每个(3列)栏

时间:2014-03-23 03:40:26

标签: php mysql arrays json google-visualization

现在,此代码从3列数据库中检索数据,并在柱形图(hAxis)中显示为一行,这意味着: -

  1. 将有一个三栏(从3列数据库中调用)
  2. 但我想用(criteria1,criteria 2,criteria3 ..)
  3. 标记每个栏
  4. 清楚示例如下表..我只想从数据库中检索存储在3列中的百分比..标准将手动标记。

     ________________________
    |CRITERIA   |PERCENTAGE |
    |-----------------------|
    |CRITERIA 1 | 64.1      |
    |-----------------------|
    |CRITERIA 2 | 11.1      |
    |-----------------------|
    |CRITERIA 3 | 21.1      |
    |-----------------------|
    

    非常感谢..

  5. 已编辑:getdata.php:

        $table = array();
        $table['cols'] = array
       (
        array('label' => 'Criteria', 'type' => 'string'),
        array('label' => 'Criteria 1', 'type' => 'number'),
        array('label' => 'Criteria 2', 'type' => 'number'),
        array('label' => 'Criteria 3', 'type' => 'number')
        );
    
       $rows = array();
       while($r = mysql_fetch_assoc($sql_query)) 
       {
              $temp = array();
              $temp[] = array('v' =>"");
              $temp[] = array('v' => (float)$r['resultsd']);
              $temp[] = array('v' => (float)$r['resultwe']); 
              $temp[] = array('v' => (float)$r['resulttre']); 
    
              $rows[] = array('c' => $temp);
    
       }
    
        $table['rows'] = $rows;
        $jsonTable = json_encode($table);
        echo $jsonTable;
    

    这是google可视化代码,名为getdata.php。:

      google.load("visualization", "1", {packages:["corechart"]});
    
      function drawVisualization()
       {
        var jsonData=null;
        var json = $.ajax
        ({
    
          url:"getdata.php?id=<?php echo $_GET['id'];?>", 
          dataType: "json",
          async: false,
    
          success: (
          function(data) 
          {
             jsonData = data;  
    
             var data = new google.visualization.DataTable(jsonData);            
    
             var options = 
             {
                title: 'SAM Histogram Results',
                hAxis: {title: " CRITERIA TYPE", titleTextStyle: {italic: false,bold: true}},  
                vAxis: {title: "PERCENTAGE (%)", titleTextStyle: {italic: false, bold: true}},
                titleTextStyle: {color: 'black', bold:'true'},  
            }
        var chart = new google.visualization.ColumnChart(document.getElementById('visualization')).
        draw(data,options);  
    
        })
        }).responseText;
      }
      google.setOnLoadCallback(drawVisualization);
    

0 个答案:

没有答案