使用Codeigniter和highcharts

时间:2017-04-10 04:13:18

标签: php codeigniter highcharts

enter image description here

enter image description here

我是使用codeigniter的新手。我们的老师要求我们在系统中设置高级图表,但图表显示在图片上。

我的观点:

$(function () {
        $('#chart-A').highcharts({
            chart: {
                type: 'column'
            },
            title: {
                text: 'Reports for Most Ordered Pizza'
            },
            subtitle: {
                text: 'Ordered Pizzas Only'
            },
            xAxis: {
                type: 'category',
                labels: {
                    rotation: -45,
                    align: 'right',
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif'
                    }
                }
            },
            yAxis: {
                min: 0,
                title: {
                    text: 'Sales (Peso)'
                }
            },
            // plotOptions: {
            //     series: {
            //         minPointLength: 0
            //     }
            // },
            legend: {
                enabled: false
            },
            tooltip: {
                pointFormat: '<b>{point.y} Pesos</b>',
            },
            series: [{
                name: 'Sales',
                data: <?php echo json_encode($pizzas);?>,
                dataLabels: {
                    enabled: true,
                    rotation: -90,
                    color: '#FFFFFF',
                    align: 'right',
                    x: 4,
                    y: 10,
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif',
                        textShadow: '0 0 3px black'
                    }
                }
            }]
        });

我的控制器:

public function tabular()
    {
        $data['pizzas'] = $this->user_model->tabular();
        var_dump($this->user_model->tabular());

        $this->load->view('template/header');
        $this->load->view('template/menubar');
        $this->load->view('template/highcharts',$data);
        $this->load->view('template/footer');

    }

我的模特:

public function tabular() {
        $this->db->select('products.name AS name, SUM(order_details.price) AS total');
        $this->db->from('order_details');
        $this->db->join('products', 'products.prod_id = order_details.prod_id', 'LEFT');
        $this->db->group_by("products.prod_id");
        $query = $this->db->get();
        foreach ($query->result() as $row){
            $results[] = array(
                'name' => $row->name,
                'total' => (float) $row->total
            );

        }
        return $results;
    }

我该如何解决这个问题?请帮帮我。

2 个答案:

答案 0 :(得分:0)

好像你错过了图表中的CSS。再次重新加载页面并按F12并检查控制台是否缺少.css文件。还要确保在PHP代码中显示启用错误,以确保后端代码正常工作而没有任何错误。

答案 1 :(得分:0)

我猜你错过了highchart的格式,其中数据要按格式化顺序传递。 看看下面的例子

[https://www.daniweb.com/programming/web-development/threads/471751/highcharts-mysql-and-codeigniter-help]