2017-10-23 25 views
2

私は、年の選択オプションを持つチャートを持っています。デフォルトでは、選択オプションは最新の年を選択しますが、この選択を通じて別の年の別のデータを見ることを選択できますオプションAjax選択コールに基づいてチャートデータを変更します

<script type="text/javascript"> 
$(document).ready(function() { 
    $('table.highchart').highchartTable(); 
    $('.btnTahun').click(function() { 
    $coba = $('#Year').val(); 
    $.ajax({ 
      type: 'POST', 
      url: "<?php echo site_url('dashboard/list_data/')?>", 
      data: {'tahun':$coba}, 
      success: function(data) { 
       $("#tableChart").html(data); 
      } 
     }); 
    }); 
}); 
</script> 

私はまだ以前に選択した年、別の年を選択してください私の見解で存在するときに問題がある、私は、それが唯一の選択された年は私のビューに表示されますことを確認以下の私の絵を見てみたいです私は2016年を選ぶことができますが、2017年のデータチャートはまだ私の見解で示されています。私はそれを望んでいません。私のAjaxには何が間違っていますか?または私のコントローラやモデルが原因で可能でしょうか?チャートを表示するために私のHTML形式の

enter image description here

構造は、あなたのコントローラ機能を呼び出す別のビューを作成しますので、あなたは、AJAXのではなく、提出フォームを使用することができます

<table id="tableChart" class="highchart" data-graph-container-before="1" data-graph-type="column"> 
<thead style="display: none"> 
    <tr> 
     <th>Month</th> 
     <th>Category Project</th> 
    </tr> 
</thead> 
<tbody style="display: none"> 
    <tr> 
     <td>Jan</td> 
     <td><?php echo $januari ?></td> 
    </tr> 
    <tr> 
     <td>Feb</td> 
     <td><?php echo $februari ?></td> 
    </tr> 
    <tr> 
     <td>Mar</td> 
     <td><?php echo $maret ?></td> 
    </tr> 
    <tr> 
     <td>Apr</td> 
     <td><?php echo $april ?></td> 
    </tr> 
    <tr> 
     <td>May</td> 
     <td><?php echo $mei ?></td> 
    </tr> 
    <tr> 
     <td>June</td> 
     <td><?php echo $juni ?></td> 
    </tr> 
    <tr> 
     <td>July</td> 
     <td><?php echo $juli ?></td> 
    </tr> 
    <tr> 
     <td>Aug</td> 
     <td><?php echo $agustus ?></td> 
    </tr> 
    <tr> 
     <td>Sep</td> 
     <td><?php echo $september ?></td> 
    </tr> 
    <tr> 
     <td>Oct</td> 
     <td><?php echo $oktober ?></td> 
    </tr> 
    <tr> 
     <td>Nov</td> 
     <td><?php echo $november ?></td> 
    </tr> 
    <tr> 
     <td>Dec</td> 
     <td><?php echo $desember ?></td> 
    </tr> 
</tbody> 

+0

はあなたの構造は、HTMLでも表示することができますか?具体的に '#tableChart'が置かれている場所 – Riyenz

+0

@Riyenz大丈夫です。私の質問を更新してください。 –

+0

@Riyenz uは私の質問をもう一度チェックできます。 –

答えて

2

下に見ることができますそれ。 HERESにフォームヘルパーのリンクhttps://www.codeigniter.com/userguide3/helpers/form_helper.html

CONTROLLER

public function list_data(){ 
    $this->load->helper('form'); 
    $thn = $this->input->post('tahun'); 
    $data['januari'] = $this->dashboard_m->get_kategori_totals('01',$thn)->num_rows(); 
    $data['februari'] = $this->dashboard_m->get_kategori_totals('02',$thn)->num_rows(); 
    $data['maret'] = $this->dashboard_m->get_kategori_totals('03',$thn)->num_rows(); 
    //And the code above will be the same until december, the differences only in the parameter 

    $data['title'] = 'Aplikasi Saranabudi'; 
    $data['aktif'] = 'Jumlah Kategori Project'; 
    $data['judul_hal']= 'Dashboard Kategori Project'; 
    $this->load->view('dashboard/kategori_project/list_data',$data); 
} 

VIEW

$attributes = array('id' => 'myID', 'name' => 'myName', 'class' => 'myClass', 'method' => 'post'); 
echo form_open('', $attributes); 
$options = array(
    '2015' => '2015', 
    '2016' => '2016', 
    '2017' => '2017', 
    '2018' => '2018', 
); 
echo form_dropdown('tahun', $options); 
// THE CHART 
echo form_submit(array('id' => 'filter_button', 'name' => 'filter_button'), 'Filter'); 
echo form_close(); 
関連する問題