Jump to content

jpgraph gantt chart and mysql array


gorio

Recommended Posts

Hi Freaks,

 

I am trying to make a gantt chart with data stored in a mysql database but I am having problems with the syntax.

 

I can create the chart ok by hard coding, and I can see the database query is returning the expected data, but I just can't quite figure the correct syntax to pass the data to jpgraph to get the result.

 

simplified code:

 

<?php require_once('connections/manager.php'); ?>
<?php

mysql_select_db($database_manager, $manager);
$query_project = "SELECT `task`, `dateStart`, `dateFinish`, `managerName` FROM `test`";
$project = mysql_query($query_project, $manager) or die(mysql_error());
$row_project = mysql_fetch_assoc($project);
$totalRows_project = mysql_num_rows($project);

require_once ('jpgraph/jpgraph.php');
require_once ('jpgraph/jpgraph_gantt.php');

$graph = new GanttGraph(800);

$graph->title->Set("Project");
$graph->ShowHeaders(GANTT_HYEAR | GANTT_HMONTH | GANTT_HDAY | GANTT_HWEEK);
$graph->scale->day->SetStyle(DAYSTYLE_SHORTDATE4);
$graph->scale->day->grid->Show();
$graph->scale->month->SetStyle(MONTHSTYLE_LONGNAME);
$graph->scale->week->SetFont(FF_FONT1);

$n=0;
  do
   {

$data[]=array(array($n,$row_project["task"],$row_project["dateStart"],$row_project["dateFinish"],$row_project["managerName"]));
++$n;

//echo "\$bar".$n." = new GanttBar(".$n.",\"".$row_project["task"]."\",\"".$row_project["dateStart"]."\",\"".$row_project["dateFinish"]."\",\"".$row_project["managerName"]."\")";

   }while
   ($row_project=mysql_fetch_array($project));

$graph->Add(array($data)); // I figure this is where I'm going wrong?

$graph->Stroke();

mysql_free_result($project);
?>

 

This is giving me the following error:

Fatal error:  Call to a member function GetMaxDate() on a non-object in jpgraph/jpgraph_gantt.php on line 630

 

Other variations bring up an error graphic saying no date value, so as I said I'm pretty sure it's a problem with passing the array to jpgraph...

 

There don't appear to be any forums at jpgraph, and other searching isn't giving me any joy so any pointers would be most welcome.

Link to comment
Share on other sites

ok I figured it out, the corrected relevent lines are:

 

$n=0;
  do
   {
$data[]=array($n++,ACTYPE_NORMAL,$row_project["task"],$row_project["dateStart"],$row_project["dateFinish"],$row_project["managerName"]));
   }while
   ($row_project=mysql_fetch_array($project));

$graph->CreateSimple($data);

 

hope this helps anyone losing hair like me

 

 

Link to comment
Share on other sites

  • 3 years later...

i copy ur corrected code but still not display the chart

it show

 

Notice: Undefined offset: 4 in C:\xampp\htdocs\gant\jpgraph_gantt.php on line 410

Notice: Undefined offset: 5 in C:\xampp\htdocs\gant\jpgraph_gantt.php on line 458
JpGraph Error: 6017 Unknown date format in GanttScale (%s).

 

maybe there is something wrong in date format...im using xampp as web server, the date format in YYYY/MM/DD

and i change the style code to code below then still the same output display

 

$graph->scale->day->SetStyle(DAYSTYLE_CUSTOM);

Edited by yon90
Link to comment
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.