如何在谷歌图表功能中显示来自mysql的数据?

时间:2014-08-23 12:47:29

标签: php mysql codeigniter google-visualization google-chartwrapper

我正在尝试使用谷歌图表来显示从mysql查询中检索到的一些数据。这是在codeigniter中完成的项目。我想知道如何显示我的查询返回的数字。我的代码如下:

控制器:

<?php
class RevProgressC extends CI_Controller
{
    public function index()
    {

    $this->load->model('PaperM');
    $this->load->model('AddRevM');
    $data['rowa']=$this->PaperM->ViewReviewed();


    $this->load->view('RevProgress',$data); 
}


}
?>

型号:

function ViewReviewed()
{

    $this->db->where('status','1');
    $this->db->or_where('status','2');

    $this->db->from('assign');
    $data = $this->db->count_all_results();
    return $data;

}

查看:

<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">


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

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

  // Callback that creates and populates a data table,
  // instantiates the pie chart, passes in the data and
  // draws it.

  //<?php $this->load->model('PaperM');
    //$data['rowa']=$this->PaperM->ViewReviewed();
  //?>

  function drawChart() {

    // Create the data table.
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Topping');
    data.addColumn('number', 'Slices');
    data.addRows([
      ['Reviewed', 5],
      ['Pending Review', 10]
    ]);

    //var data = google.visualization.arrayToDataTable(raw_data);

    // Set chart options
    var options = {'title':'Reviewed and Not Reviewed Papers',
                   is3D: true,};

    // Instantiate and draw our chart, passing in some options.
    var chart = new google.visualization.PieChart(document.getElementById('piechart_3d'));
    chart.draw(data, options);
  }
</script>

而不是5和10,我想使用一个php变量,它将保存上述函数的值。然后将其传递给脚本。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

更改这些行..

在控制器上

$this->load->view('RevProgress',$data);

$this->load->view('RevProgress',json_encode($data));

**和观看PAge **

data.addRows([ ['Reviewed', 5], ['Pending Review', 10] ]);

data.addRows(<?php echo $RevProgress;?>);