Javascript 将数据库中的数据插入google chart codeigniter

Javascript 将数据库中的数据插入google chart codeigniter,javascript,html,mysql,codeigniter,Javascript,Html,Mysql,Codeigniter,我想将数据从两个表插入到google图表中,以获取销售报告。我在模型页面中尝试了联接查询,但结果是饼图div中没有数据 表sales中的数据如下所示 id | person_name | sales_id | status 1 Michael 2 1 2 Daniel 2 3 3 James

我想将数据从两个表插入到google图表中,以获取销售报告。我在模型页面中尝试了联接查询,但结果是饼图div中没有数据

表sales中的数据如下所示

id |    person_name  |      sales_id     |     status
 1       Michael                2                 1
 2       Daniel                 2                 3
 3       James                  2                 1
 4       Ricky                  1                 2
 5       Martin                 1                 3
id |        status        |       color 
 1       Meeting                 #f00630
 2       Presentation            #f2478f     
 3       Proposal Sent           #170303       
 4       Invoice                 #7cb342 
 5       Lost                    #fe0725
function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Type', 'Total'],
      ['Meeting', 2],
      ['Presentation', 0],
      ['Proposal Sent', 1],
      ['Invoice', 0],
      ['Lost', 0]
    ]);

    var options = {
      is3D: true,
      colors: ['#f00630', '#f2478f', '#170303', '#7cb342', '#fe0725']
    };

    var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    chart.draw(data, options);        
  }
表状态中的数据如下所示

id |    person_name  |      sales_id     |     status
 1       Michael                2                 1
 2       Daniel                 2                 3
 3       James                  2                 1
 4       Ricky                  1                 2
 5       Martin                 1                 3
id |        status        |       color 
 1       Meeting                 #f00630
 2       Presentation            #f2478f     
 3       Proposal Sent           #170303       
 4       Invoice                 #7cb342 
 5       Lost                    #fe0725
function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Type', 'Total'],
      ['Meeting', 2],
      ['Presentation', 0],
      ['Proposal Sent', 1],
      ['Invoice', 0],
      ['Lost', 0]
    ]);

    var options = {
      is3D: true,
      colors: ['#f00630', '#f2478f', '#170303', '#7cb342', '#fe0725']
    };

    var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    chart.draw(data, options);        
  }
我需要根据销售id将数据状态类型、数字中的总状态和颜色状态插入谷歌饼图。我需要更改我手动写入的数据,如下所示

id |    person_name  |      sales_id     |     status
 1       Michael                2                 1
 2       Daniel                 2                 3
 3       James                  2                 1
 4       Ricky                  1                 2
 5       Martin                 1                 3
id |        status        |       color 
 1       Meeting                 #f00630
 2       Presentation            #f2478f     
 3       Proposal Sent           #170303       
 4       Invoice                 #7cb342 
 5       Lost                    #fe0725
function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Type', 'Total'],
      ['Meeting', 2],
      ['Presentation', 0],
      ['Proposal Sent', 1],
      ['Invoice', 0],
      ['Lost', 0]
    ]);

    var options = {
      is3D: true,
      colors: ['#f00630', '#f2478f', '#170303', '#7cb342', '#fe0725']
    };

    var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
    chart.draw(data, options);        
  }
这是我在模型页面中尝试过的脚本

 public function getAllStatus()
 {
    $this->db->select('status');
    $this->db->from('sales');
    $this->db->join('sales_status', 'sales_status.id = sales.status');
    $this->db->where('sales_id', $id);
    return $query = $this->db->get();
 }
下面是控制器页面中的脚本

这是查看页面中的脚本

你知道我要修什么地方吗


谢谢

图表需要JSON对象和数据。您可以尝试像以前一样使用循环构建类似JSON的结构,但只输出JSON对象要简单得多

在您看来,在调用图表之前:

var first_data = <?php echo json_encode($your_first_var); ?>;
var second_data = <?php echo json_encode($your_second_var); ?>;

您的查询没有给出任何错误?只是在饼图中没有显示任何数据