数据集未显示在图形上

时间:2020-04-25 09:59:05

标签: javascript php html ajax canvasjs

计划是使用php表中的数据制作线形图。画布会显示出来,并且轴会出现,但折线图不会出现。当我检查google inspector时,它表明php表中的数据已加载到数组中。可能是什么问题。我在下面包含了php代码和脚本代码。

$sql= "SELECT Month, Reviews FROM avg_reviews" ;
$result = mysqli_query($db,$sql);

$dataX ="";
$dataY="";

While($row=mysqli_fetch_assoc($result)){
    $dataX = $dataX . "'". $row['Month']."',";
    $dataY = $dataY. "'". $row['Reviews']."',";}


$dataX=trim($dataX,",");
$dataY=trim($dataY,",");

?>

<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
    animationEnabled: true,
    title:{
        text: "Website Traffic"
    },

    axisY: {
        title: "Number of Visitors",
        includeZero: false,
        scaleBreaks: {
            autoCalculate: true
        }
    },
    data: [{
        type: "line",
         labels:[<?php echo $dataX; ?>],

        color: "#F08080",
             datasets:[
     {data:[<?php echo $dataY; ?>],}
     ]

    }]
});
chart.render();

}
</script>

0 个答案:

没有答案
相关问题