Jump to content

Chart not displaying properly


Go to solution Solved by Barand,

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.