简体   繁体   English

谷歌图表:点击节点链接导航到其他页面

[英]Google chart : Navigating to other page on click of the node link

Hi I am using google organisation charts for my web application in Codeigniter- PHP/Mysql.您好,我在 Codeigniter- PHP/Mysql 中为我的 Web 应用程序使用谷歌组织结构图 I have loaded the nodes of my chart from mysql database.我已经从 mysql 数据库加载图表的节点。 And the text in the nodes are made as links.节点中的文本作为链接。 Everything is fine till now.到目前为止一切都很好。 But now I want to add href to the link, so that when user clicks on the link it should navigate to the details page, where the details of particular node is shown.但现在我想将 href 添加到链接中,这样当用户单击链接时,它应该导航到详细信息页面,其中显示了特定节点的详细信息。 I know, in order to show the details, there should be an Id of the node to fetch the data from database.我知道,为了显示细节,应该有一个节点的 Id 来从数据库中获取数据。 So here's my question How can I add this id to the link?所以这是我的问题如何将此 ID 添加到链接?

Is there any way to do this?有什么办法吗? Can anyone please help me.谁能帮帮我吗。 Here is my code:这是我的代码:

model:模型:

public function getTreeMembersData()
{
    $this->db->select('E1.name AS memname,E2.name AS parentname,E3.name AS spouse');
    $this->db->from('tab_members AS E1');
    $this->db->join('tab_members AS E2', 'E2.member_id = E1.parent_id','left outer');
    $this->db->join('tab_members AS E3', 'E3.parent_id = E1.member_id AND E3.relation_id = 3','left outer');
    $this->db->where('E1.relation_id !=', 3);
    $query = $this->db->get();
    return $query->result();
}

Controller:控制器:

public function membertree()
{
    if(isset($_SESSION['username']) || isset($_SESSION['userid']))
    {
        $page['pagename'] = "membertree";
        $data['msg'] = $this->session->flashdata('msg');
        $this->load->view('header',$page);
        $data['treedata'] = $this->Family_model->getTreeMembersData();
        $this->load->view('membertree',$data);
        $this->load->view('footer');
    }
    else
    {
        redirect('Auth/login');
    }
}

View:看法:

<script type="text/javascript">
    var url="<?php echo base_url();?>";
  google.charts.load('current', {packages:["orgchart"]});
  google.charts.setOnLoadCallback(drawChart);
    var data;
    var chart;

  function drawChart() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('string', 'Parent');

      data.addRows([<?php 
          foreach($treedata as $d)
          {  
              $memname = $d->memname;
              $parent = $d->parentname;
              $spouse = $d->spouse;
              ?>
          [{v:'<?php echo $memname;?>', f:'<a><?php echo $memname;?><a><div><a><?php echo $spouse;?></a></div>'},'<?php echo $parent; ?>'],
        <?php
          }
      ?>]);
      var options = {
                 'width':250,
                 'height':600};
    // Create the chart.
    var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
    // Draw the chart, setting the allowHtml option to true for the tooltips.
    chart.draw(data, {allowHtml:true});
      google.visualization.events.addListener(chart, 'select', selectHandler);

function selectHandler() {
  var selectedItem = chart.getSelection()[0];
if(selectedItem) {
    var name = data.getValue(selectedItem.row,0);
    alert(name);
 }
}
  }

  <div class="box">
    <div class="box-body">
            <div id="chart_div" class="chart"></div>
    </div>
   </div>

if you are able to get the id from the query,如果您能够从查询中获取 id,
you can add in the address to the details page as a 'GET' parameter in the href attribute.您可以将地址作为href属性中的'GET'参数添加到详细信息页面。

something like...就像是...

<a href="http://address.to/details.php?id=<?php echo $id_field;?>"><?php echo $memname;?><a>

as in the data row...如数据行...

[{v:'<?php echo $memname;?>', f:'<a href="http://address.to/details.php?id=<?php echo $id_field;?>"><?php echo $memname;?><a><div><a><?php echo $spouse;?></a></div>'},'<?php echo $parent; ?>'],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM