chart.js AJAX laravel未捕获到TypeError:无法读取未定义的属性'fontSize'

时间:2018-08-20 12:13:12

标签: jquery ajax laravel chart.js

我正在尝试通过AJAX获取chart.js数据,这将返回错误

  

“未捕获的TypeError:无法读取未定义的属性'fontSize'”

尝试过jquery ajax,同样的错误

尝试过此测试之后,测试了不同的chartjs版本,相同的错误

$(document).ready(function() {
    showGraph();
});

function showGraph()
{
    {
        $.post("/data?_token="+$('meta[name="csrf-token"]').attr('content'),
        function (data)
        {
            console.log(data);
            var name = [];
            var marks = [];

            for (var i in data) {
                name.push(data[i].student_name);
                marks.push(data[i].marks);
            }

            var chartdata = {
                labels: name,
                datasets: [
                    {
                        label: 'Student Marks',
                        backgroundColor: '#49e2ff',
                        borderColor: '#46d5f1',
                        hoverBackgroundColor: '#CCCCCC',
                        hoverBorderColor: '#666666',
                        data: marks
                    }
                ]
            };
            var graphTarget = $("#graphCanvas");
            var barGraph = new Chart(graphTarget, {
                type: 'bar',
                data: chartdata
            });
        });
    }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>

<canvas id="graphCanvas" width="0" height="400"></canvas>

0 个答案:

没有答案