круговая диаграмма canvasjs, получающая данные из mysql

$con = mysqli_connect("localhost","root","","final_osa");

if (mysqli_connect_errno($con))
{
echo "Failed to connect to DataBase: " . mysqli_connect_error();
}else
{
$data_points = array();

$result = mysqli_query($con, "SELECT * FROM scholars_list");

while($row = mysqli_fetch_array($result))
{
$point = array("label" => $row['course'], "y" => $row['student_name']);

array_push($data_points, $point);
}

echo json_encode($data_points, JSON_NUMERIC_CHECK);
}
mysqli_close($con);

Как я могу сделать круговую диаграмму, которая будет составлять процент от того, сколько студентов на курсе зачислено со стипендиатом? Спасибо

вот мой JS
$ (документ) .ready (function () {

            $.getJSON("data.php", function (result) {

var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
exportEnabled: true,
data: [
{
type: "pie",
showInLegend: "true",
legendText: "{label}",
indexLabelFontSize: 16,
indexLabel: "{label} - #percent%",
yValueFormatString: "฿#,##0",
dataPoints: result
}
]
});

chart.render();
});
});

-1

Решение

Формат данных, как это

Предположим, что $ records содержит ваши данные:

$data=array();
foreach ($records as $record) {
$data[] = array(
"label"=>$record["student_name"],
"y"=>$record['course'], //percentage value
);
}
echo json_encode($data);

Js часть:

var chart = new CanvasJS.Chart("chartContainer", {
title:{
text: "Monthly User work details"},
data: [
{
// Change type to "doughnut", "line", "splineArea", etc.
type: "pie",
showInLegend: "true",
legendText: "{label}",
indexLabelFontSize: 16,
indexLabel: "{label} - #percent%",
yValueFormatString: "฿#,##0",
dataPoints: JSON.parse(result)
}
]
});
chart.render();
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector