PHPlot仅显示MySQL的3个结果中的2个

时间:2014-01-23 20:17:49

标签: php mysql graph charts pie-chart

我有一个饼图,我想要它显示3个结果。我正在使用2线图表中的代码并且工作正常,我只是希望它显示所有3个结果。图例显示全部3,但图表仅显示前两个。我知道我的代码中有错误,我找不到它。有什么建议吗?

$sql1 = "SELECT totaldep, totalmania, totalanxiety FROM $dbmood ORDER BY DATE ASC";

//Define the object


$rslt1 = @mysql_query($sql1, $conn) or die("Couldn't execute select:".@mysql_error());   

// I'm assuming it's somewhere in here, I just can't see it
 $iid = "-1";
        while($row = mysql_fetch_row($rslt1)) {

                if ($row[0] != $iid)     {
                        $iid = $row[0];
                } else {
                    $row[0] = '';
            }
// between there and here

            $graph_data[] = $row;           

//Define some data
$example_data = $graph_data;

        }




//Define the object
$graph =& new PHPlot(300,250);
$graph->SetPlotType("pie");
$legend = array();
$legend[] = "Depression";
$legend[] = "Mania";
// It isn't showing anxiety, everything else is showing/updating fine
$legend[] = "Anxiety";


$graph->SetDataValues($example_data);
$graph->SetLegendPixels(1,5,false);
$graph->SetLegend($legend);

//Draw it
$graph->DrawGraph();

先谢谢,你们总是帮忙!

1 个答案:

答案 0 :(得分:0)

我通过单独拉出它来修复它

$datab = mysql_select_db( 'medtrack', $conn ) or die(mysql_error());

$sql1 = "SELECT * FROM $dbmood ORDER BY DATE ASC";



$getit = mysql_query ( $sql1, $conn );

while($row = mysql_fetch_array($getit, MYSQL_ASSOC))
{
$dep="{$row['totaldep']}";
$man="{$row['totalmania']}";
$anx="{$row['totalanxiety']}";


$example_data = array(
array('a',$dep,$man,$anx)
);
}


//Include the code

//Define the object
$graph =& new PHPlot(300,250);
$graph->SetPlotType("pie");
$legend = array();
$legend[] = "Depression";
$legend[] = "Mania";
$legend[] = "Anxiety";


$graph->SetDataValues($example_data);
$graph->SetLegendPixels(1,5,false);
$graph->SetLegend($legend);
//Draw it
$graph->DrawGraph();