Jump to content

Chart not displaying properly


dapcigar

Recommended Posts

Am trying to query my DB and use the result to create a chart. code pasted below;

 

<?php

$date = $_POST['Date'];

//$date = '25/05/2010';
$date = str_replace('/', '-', $date);

$new_date =  date('Y-m-d', strtotime($date));
//echo $new_date;

include('mysql_connect.php');



// Settings for the graph

include "libchart/classes/libchart.php";

 $chart = new VerticalBarChart(600, 520);

    $chart = new VerticalBarChart();

$dataSet = new XYDataSet();

 $query1 =  mysql_query ("select * from requisition where date = '$new_date' ") or die(mysql_error());
 
 while($row = mysql_fetch_array($query1))
{
    //$amt = $row['amount'];
    // check each department and sum up all their data
    
    if ( $row['department'] = "ICT")
    {
        $total1 = $total1 + $row['amount'];
        //exit;
        
    }
    
    else if ( $row['department'] = "Supply Chain/ Asset Integrity")
    {
        $total2 = $total2 + $row['amount'];
        //exit;
        
    }
    
    else if ( $row['department'] = "Account")
    {
        $total3 = $total3 + $row['amount'];
        //exit;
        
    }
    
    else if ( $row['department'] = "Admin / Services
")
    {
        $total4 = $total4 + $row['amount'];
        //exit;
        
    }
    
        else if ( $row['department'] = "Business Development")
    {
        $total5 = $total5 + $row['amount'];
        //exit;
        
    }
    
        else if ( $row['department'] = "Manpower")
    {
        $total6 = $total6 + $row['amount'];
        //exit;
        
    }
    
    else if ( $row['department'] = "Maintenance")
    {
        $total7 = $total7 + $row['amount'];
        //exit;
        
    }
    
    else if ( $row['department'] = "HR")
    {
        $total8 = $total8 + $row['amount'];
        //exit;
        
    }
    
    else if ( $row['department'] = "Marine Logistics")
    {
        $total9 = $total9 + $row['amount'];
        //exit;
        
        
        
    }
//$dataSet->addPoint(new Point($row['department'], $row['amount']));

}
$dataSet->addPoint(new Point("ICT", $total1));
$dataSet->addPoint(new Point("Supply Chain", $total2));
$dataSet->addPoint(new Point("Account", $total3));
$dataSet->addPoint(new Point("Admin / Services", $total4));
$dataSet->addPoint(new Point("Business Development", $total5));
$dataSet->addPoint(new Point("Manpower", $total6));
$dataSet->addPoint(new Point("Maintenance", $total7));
$dataSet->addPoint(new Point("HR", $total8));
$dataSet->addPoint(new Point("Logistics", $total9));


$chart->setDataSet($dataSet);

$chart->setTitle("Report By Date - $date");
    $chart->render("generated/date.png");
    
    header("Location: view_date.php");
    //header ('lcoation : ');

?>

 

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

When i Try to view the result, it only displays the first one in the IF statement. please, what am i doing wrong?

 

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/288600-chart-not-displaying-properly/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.