通过Ajax Uncaught TypeError呈现图表时:无法读取属性' getTime'未定义的

时间:2015-08-14 18:52:54

标签: php ajax canvasjs

当我尝试使用ajax传回的数据渲染图表时,我收到错误,"未捕获的TypeError:无法读取属性' getTime'未定义"。

        $.ajax({
            type        : 'POST',
            url         : 'admin-controllers/chart-contorller.php',
            dataType    : 'json',
            encode      : true
        })
        .done(function(data) {
                alert('contorller');
                if ( success) {
                    var dataPoints = data.graphData;
                    console.log(dataPoints);
                    var chart = new CanvasJS.Chart("timeToSetChart", {
                        title:{
                                text: "User Time to initialy set DNS",
                                fontSize: 20,
                            },
                            axisX:{
                                labelFontSize: 12
                            },
                            axisY: {
                                title: "Number of users",
                                titleFontSize: 14,
                                labelFontSize: 12
                            },
                            data: [{
                                type : 'column',
                                dataPoints: data.graphData
                            }]
                    });
                    chart.render();


                }

我的字符串data.graphData返回:

[{x: 10, y: 0, label: "1hours"},{x: 20, y: 0, label: "2hours"},{x: 30, y: 16, label: "6hours"},{x: 40, y: 0, label: "12hours"},{x: 50, y: 0, label: "24hours"},{x: 60, y: 0, label: "2days"},{x: 70, y: 0, label: "3days"},{x: 80, y: 0, label: "4days"},{x: 90, y: 0, label: "5days"},{x: 100, y: 0, label: "6days"},{x: 110, y: 0, label: "7days"},{x: 120, y: 3, label: "8plusdays"},]

当我将它粘贴到dataPoints变量时,它可以正常工作。

0 个答案:

没有答案