无法在php中的mysql数据库中显示饼图中的值
问题描述:
I want to draw a pie chart where value will be taken from MySQL database. But it is not working. But if I give the manual value then the pie chart is showing. Below is my code:
<?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();
?>
But if I give the manual value in below two fields then it is working. Anyone please help.
$dataSet->addPoint(new Point("Success", 20));
$dataSet->addPoint(new Point("Failed", 80));
答
try this
...
$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));
...