简体   繁体   English

如何从控制器获取数据以查看(Highchart)PHP Codeigniter

[英]how to get data from controller to view (highchart) php codeigniter

I wanna see the value of series Highchart, but when I debug it just not show the values. 我想查看Highchart系列的值,但是在调试时只是不显示值。 This is my code 这是我的代码

and this is my view 这是我的看法

<script type="text/javascript" src="<?php echo base_url(); ?>public/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/highcharts-3d.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/modules/exporting.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>public/highcharts/js/themes/grid-light.js"></script>

<style type="text/css">
</style>        


<script type="text/javascript">
    var chart1;
    jQuery(document).ready(function(){
        chart1 = new Highcharts.Chart({
            chart: {
                renderTo: 'container',
                type: 'column',
                borderWidth: 2,
                animation: {
                    duration: 1000
                },
                spacingRight: 25,
                backgroundColor: {
            linearGradient: [0, 0, 500, 500],
            stops: [
                [0, 'rgb(255, 255, 255)'],
                [1, 'rgb(229, 238, 238)']
            ]
        },
            },
            tooltip: {
                backgroundColor: '#FCFFC5',
                shadow: true,
            },

            title: {
                text: 'Store Chart'
            },
            credits: {
                enabled: false
            },
            xAxis: {
                categories: [<?php echo "'".implode("','",$branch_name)."'";?>]
            },
            yAxis: {
                title: {
                    text: 'Tingkat Penjualan'
                }
            },


            exporting: {
                buttons: {
                contextButton: {
                text: 'Export'
                    }
                }
            },
            series: [<?php echo "'".implode("','",$branch_sell)."'";?>],
                 plotOptions: {
            series: {
            color: '#66B2FF'
            }
        }


        });

        });
        </script>

and this is controller 这是控制器

public function index()
{

    $data = array();
    $this->menu_handler->set_header($data,1,0);
    $this->load->model('m_admin');
    $get_branch         = $this->m_admin->get_chart_store();

    $get_selling_store  = $this->m_admin->get_sell_store();


    $data['branch_name'] = array();

    $data['branch_sell'] = array();

    for($i=0,$n=count($get_branch); $i<$n; $i++)
    {
        $data['branch_name'][] = $get_branch[$i]->NAMA_CABANG;
    }

    for($i=0,$n=count($get_selling_store); $i<$n; $i++)
    {
        $data['branch_sell'][]  = $get_selling_store[$i]->rslt;
    }
    $series_data[]  = array('name' => 'Branch Store', 'data' => array($get_selling_store));



    $data['series_data'] = json_encode($series_data);


    $this->load->view('welcome_message', $data);
    global $file_counter,$error_file,$size_counter; 

}

and this is my model 这是我的模特

<?php if (!defined('BASEPATH'))
exit('No direct script access allowed');
function get_chart_store($id_store=''){
    global $sec_database;
    if(empty($id_store))
    {
        $get_detail = $sec_database->select('*')->get('MST_CABANG')->result();
    }
    else
    {
        $get_detail = $sec_database->select('*')->where('CABANG_ID',$id_store)->get('MST_CABANG')->result();
    }

    if(count($get_detail) > 0)
    {
        return $get_detail;
    }
    else
    {
        return 1;   
    }
}

function get_sell_store($id_sell='')
{
    global $sec_database;
    $q_detailstore = "
        SELECT
        sd.CABANG_ID,
        sd.`NAMA_CABANG`,
        SUM(SALES_TOTAL) as rslt

        FROM
        MST_SALES as md
        RIGHT JOIN MST_CABANG as sd
        ON md.`CABANG_ID` = sd.CABANG_ID

        GROUP BY
        sd.CABANG_ID 
    ";
    $get_detail_selling = $sec_database->query($q_detailstore,array($id_sell))->result();
    if(count($get_detail_selling) > 0)
    {
        return $get_detail_selling;
    } 
    else
    {
        return 1;
    }

}

the chart just show the series, but how I can get value of series to the chart? 图表只是显示序列,但是如何获得图表的序列值? sorry I'm newbie.. thx before 对不起,我是新手。

implode() does't work with multidimensional array. implode()不适用于多维数组。 so It's not printing value 所以这不是印刷价值

try 尝试

$data['branch_name'] = $get_branch[$i]->NAMA_CABANG;

instead of 代替

$data['branch_name'][] = $get_branch[$i]->NAMA_CABANG;

in your controller. 在您的控制器中。 same as for your branch_sell variable 与您的branch_sell变量相同

UPDATE 更新

for($i=0,$n=count($get_branch); $i<$n; $i++)
{
    $data['branch_name'] = $get_branch[$i]->NAMA_CABANG;
}

array_walk($data['branch_name'],function (&$val){ $val="'".$val."'";});

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

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