在chart-js中显示数据库中的波斯数据的问题

时间:2019-02-22 17:16:04

标签: chart.js

我想从phpmyadmin中读取一些数据,并使用chart-js进行显示,但是我在图表中显示标签时遇到了问题,即显示给我??????我不知道是什么问题。

这是两个页面之一。

<?php

header('Content-type: application/json; charset=utf-8');

//header('Content-Type: text/html; charset=utf-8');



$conn = mysqli_connect("localhost","root","root","database");


$sqlQuery = "SELECT personname,pointe FROM result ORDER BY pointe";

$result = mysqli_query($conn,$sqlQuery);


$data = array();
foreach ($result as $row) {
    $data[] = $row;
}



mysqli_close($conn);

echo json_encode($data);
?>

这是另一页。

    <!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<meta charset="UTF-8">

<title>Creating Dynamic Data Graph using PHP and Chart.js</title>
<style type="text/css">
BODY {
    width: 550PX;
}

#chart-container {
    width: 100%;
    height: auto;
}
</style>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/Chart.min.js"></script>


</head>
<body>
    <div id="chart-container" style="position: relative;" >
        <canvas id="graphCanvas"></canvas>
    </div>

    <script >
        $(document).ready(function () {
            showGraph();
        });


        function showGraph()
        {
            {
                $.post("data.php",
                function (data)
                {
                    console.log(data);
                     var personname = [];
                    var pointe = [];

                    for (var i in data) {
                        personname.push(data[i].personname);
                        pointe.push(data[i].pointe);
                    }

                    var chartdata = {
                        labels: personname,
                        datasets: [
                            {
                                label: 'نتایج مسابقات',
                                backgroundColor: '#49e2ff',
                                borderColor: '#46d5f1',
                                hoverBackgroundColor: '#CCCCCC',
                                hoverBorderColor: '#666666',
                                data: pointe
                            }
                        ]
                    };

                    var graphTarget = $("#graphCanvas");

                    var barGraph = new Chart(graphTarget, {
                        type: 'bar',
                        data: chartdata
                    });
                });
            }
        }
        </script>

</body>
</html>

我数据库中的数据是波斯语言。 我附上下面的图片: enter image description here

0 个答案:

没有答案