TypeError:无法读取p._processMultiseriesPlotUnit处未定义的属性“ x”

时间:2019-02-19 10:15:08

标签: javascript php jquery canvasjs

大家好,我试图在我的网站中添加一个图形,正在使用名为canvas.js的jquery插件,并使用php从mysql数据库中获取数据,但是当我尝试加载页面时,会在我的控制台中得到它,

TypeError: Cannot read property 'x' of undefined     at p._processMultiseriesPlotUnit

这是我的php代码

<?php 
    require_once '../../include/dbcon2.php';

    $dataPoints = array();    
    $groups = array();
    $data = mysqli_query($newconn, "SELECT SUM(sales_order.quantity) AS quantity, order_details.date_time, 
        sales_order.id FROM order_details
        INNER JOIN sales_order ON sales_order.order_id = order_details.order_id 
        WHERE order_details.payment_status = 'Approved' GROUP BY sales_order.order_id ");
    while ($row = mysqli_fetch_array($data)) {   
        $mydate = $row['date_time'];
        $quantity = $row['quantity'];
        $date = date("Y-m",strtotime($mydate));        
        array_push($dataPoints, array("label" =>  $date ,"y" =>  $quantity));            
    }
    foreach ($data as $item) {
        $key = $item['label'];
        if (!array_key_exists($key, $groups)) {
            $groups[$key] = array('label' => $item['label'],'y' => $item['y'], );
        } else {
            $groups[$key]['y'] = $groups[$key]['y'] + $item['y'];
        }
    }
    echo json_encode($groups, JSON_NUMERIC_CHECK);
?>

和我从数据库中获取数据的Javascript代码是

function getDeydataGraph(dataPoints, GraphTheme, GraphType){
        var chart = new CanvasJS.Chart("chartContainer", {
            theme: GraphTheme,
            animationEnabled: true,
            exportEnabled: true,
            title: {
                text: "Sales Report"
            },
            axisY: {
                title: "Amount ",
                includeZero: true,        
            },
            legend:{
                cursor: "pointer",
                itemclick: toggleDataSeries
            },
            toolTip: {
                shared: true
            },
            data: [
            {
                type: GraphType,
                name: "Dte",
                showInLegend: "true",      
                dataPoints: dataPoints
            }]
        });

        chart.render();
        function toggleDataSeries(e){
            if (typeof(e.dataSeries.visible) === "undefined" || e.dataSeries.visible) {
                e.dataSeries.visible = false;
            }
            else{
                e.dataSeries.visible = true;
            }
            chart.render();
        }
        return chart;
    }
$(document).ready(function () {
        var GraphTheme = "light1";
        var GraphType = "spline";
        var thedataPoints;
        $.getJSON("everything/processing/graph.php", function (dataPoints) {   
            thedataPoints = dataPoints
            console.log(dataPoints)
            getDeydataGraph(thedataPoints, GraphTheme, GraphType);
        });
});

请帮助我,我在做错什么以及如何解决此问题。 谢谢

0 个答案:

没有答案