在laravel项目

时间:2017-09-12 19:18:14

标签: php laravel-5 chart.js

我正在尝试使用chartJs在我的laravel项目上绘制一个条形图,但我收到了这个错误 - “无法创建图表:无法从给定项目获取上下文”。 我试过调试,我觉得一切都很好。

这是我的JS文件

$(document).ready(function () {
    $.ajax({
        url: "{{url('properties','totalTaxPaidByLga')}}",
        method: "GET",
        success: function(data) {
            console.log(data);
            var player = [];
            var score = [];

            for(var i in data) {
                player.push("Player " + data[i].playerid);
                score.push(data[i].score);
            }

            var chartdata = {
                labels: player,
                datasets : [
                    {
                        label: 'Player Score',
                        backgroundColor: 'rgba(200, 200, 200, 0.75)',
                        borderColor: 'rgba(200, 200, 200, 0.75)',
                        hoverBackgroundColor: 'rgba(200, 200, 200, 1)',
                        hoverBorderColor: 'rgba(200, 200, 200, 1)',
                        data: score
                    }
                ]
            };

            var ctx = $("#mycanvas");

            var barGraph = new Chart(ctx, {
                type: 'bar',
                data: chartdata
            });

        },
        error: function(data) {
            console.log(data);
        }
    });
});

这是我的刀片文件

 <div id="chart-container">
        <canvas id="mycanvas"> </canvas>
        <p>Hi</p>
    </div>

这是我的控制器

 public function totalTaxPaidByLga(){
        $query = DB::select("select SUM(a.settlement_amount) as totalTaxPaid, d.local_name  from settlements as a, assessments as b,
        property_details as c, locals as d
        where a.assessment_ref = b.assessment_ref  and
                b.property_id = c.id and
                c.lga_id = d.local_id
        GROUP BY d.local_id");
        foreach ($query as $row) {
            $data[] = $row;
        }

        print json_encode($data);

    }

0 个答案:

没有答案