我想画一个饼图,将从MySQL数据库中获取值。但这是行不通的。但是,如果我提供手动值,则会显示饼图。下面是我的代码:

<?php
include "libchart/classes/libchart.php";

header("Content-type: image/png");

$chart = new PieChart(500, 260);
$con=mysqli_connect("localhost","root","","bkash");
// Check connection
if (mysqli_connect_errno())
{
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT count(*) FROM dialer_rate where mno='tnr' and success=1 ");
$result1 = mysqli_query($con,"SELECT count(*) FROM dialer_rate where mno='tnr' and failed=1");
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Success", $result));
$dataSet->addPoint(new Point("Failed", $result1));
#$dataSet->addPoint(new Point(" (50)", 50));
$chart->setDataSet($dataSet);

$chart->setTitle("bKash USSD Dialer Success/Fail rate");
$chart->render();
?>


但是,如果我在下面两个字段中提供手动值,则它可以正常工作。有人请帮忙。

$dataSet->addPoint(new Point("Success", 20));
$dataSet->addPoint(new Point("Failed", 80));

最佳答案

尝试这个

...
$result = mysqli_query($con,"SELECT count(*) as count FROM dialer_rate where mno='tnr' and success=1 ");
$result1 = mysqli_query($con,"SELECT count(*) as count1 FROM dialer_rate where mno='tnr' and failed=1");
$result = $result->fetch_object();
$result1 = $result1->fetch_object();
$dataSet = new XYDataSet();
$dataSet->addPoint(new Point("Success", $result->count));
$dataSet->addPoint(new Point("Failed", $result1->count1));
...

关于php - 无法在PHP中的mysql数据库的饼图中显示值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28446755/

10-13 02:49