设置图表以在Codeigniter中显示数据库中的分组记录

时间:2019-02-20 22:14:27

标签: javascript php codeigniter charts

我正在设置一份捐赠遗产中收集的金额的报告摘要,我设法从数据库中获取数据并显示在图表上。我打算按月显示按遗产分组的所有付款。 我希望y axis支付一定的金额,而x axis拥有几个月的时间,然后按estatename对结果进行分组,但是我不确定如何正确实施。

这是我所做的事情:

enter image description here

document.addEventListener('DOMContentLoaded', function () {

        var line_chart = c3.generate({
            bindto: '#c3-line-chart',
            point: {
                r: 4
            },
            size: {height: 400},
            color: {
                pattern: ['#4CAF50', '#F4511E', '#1E88E5']
            },
            data: {
                columns: [

                        <?php
                            $allestates=$this->db->query("select distinct(estate) from bookings order by estate desc")->result_array();
                            if(count($allestates)>0) {
                                foreach ($allestates as $singleestate):
                                    $thisestate=$singleestate['estate'];
                                $fetchestate=$this->db->query("select estatename from tbl_estates where id='$thisestate'")->row();
                                $thisname = $fetchestate->estatename;
                                echo '['.'\''.ucwords($thisname).'\''.',';
                                    $allpayments = $this->db->query("select amountpaid from bookings where estate='$thisestate'")->result_array();
                                    foreach ($allpayments as $payments):
                                        echo $payments['amountpaid'].',';
                                    endforeach;
                                    echo '],';
                                endforeach;
                            }else{
                        ?>
                        ['Hazina', 30, 200, 100, 400, 150, 250],
                    ['Hill Side', 50, 20, 10, 40, 15, 25]
                    <?php }?>
                ],
                type: 'spline'
            },
            grid: {
                y: {
                    show: true
                }
            }
        });

        // Resize chart on sidebar width change
        $(".sidebar-control").on('click', function () {
            line_chart.resize();
        });
    });

0 个答案:

没有答案