在Codeigniter 3.0中使用Google API的动态图表

时间:2016-04-18 09:24:36

标签: codeigniter google-api

我使用Google API根据我的月份结果显示图表并安装,所以我采用以下代码显示图表,我有静态值,但我想提供动态值

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
     <script type="text/javascript">
  google.charts.load('current', {'packages':['bar']});
  google.charts.setOnLoadCallback(drawChart);
  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Year', 'Sales', 'Expenses', 'Profit'],
      ['2014', 1000, 400, 200],
      ['2015', 1170, 460, 250],
      ['2016', 660, 1120, 300],
      ['2017', 1030, 540, 350]
    ]);

    var options = {
      chart: {
        title: 'Company Performance',
        subtitle: 'Sales, Expenses, and Profit: 2014-2017',
      }
    };

    var chart = new google.charts.Bar(document.getElementById('columnchart_material'));

    chart.draw(data, options);
  }
</script>

这是我的控制器

public function overviews()
{

$data['monthlyTotals'] = $this->livemerchant_model->overviews();
if ($this->input->post('transactionMerchant,transactionYear')) {
    $data['monthlyTotals'] = $this->livemerchant_model->overviews($this->input->post('transactionMerchant'), $this->input->post('transactionYear'));
} else {
    $data['monthlyTotals'] = $this->livemerchant_model->overviews();
}


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

这是我的模特

function overviews($theYear='',$theMonth='')
{
$this->db->select("DATEPART(Year, TRANS_TransactionDate) [TheYear],    DATEPART(Month, TRANS_TransactionDate) [TheMonth], DATENAME(Month,  TRANS_TransactionDate) [TheMonthName], SUM(TRANS_Amount) [TotalAmount]",  false);
$this->db->from('BTBL_Transactions');

if ($theYear != '') {
    $this->db->where("DATEPART(Year, TRANS_TransactionDate) = '" .    $theYear . "'", NULL, FALSE);
}

if ($theMonth != '') {
    $this->db->where("DATEPART(Month, TRANS_TransactionDate) = '" .      $theMonth . "'", NULL, FALSE);
}



$this->db->group_by("DATEPART(Year, TRANS_TransactionDate),      DATEPART(Month, TRANS_TransactionDate), DATENAME(Month,   TRANS_TransactionDate)");
$this->db->order_by("1", "asc");
$this->db->order_by("2", "asc");
$this->db->order_by("3", "asc");


$query = $this->db->get();
//echo $this->db->last_query();die();
return $query->result();
}

0 个答案:

没有答案