|
Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-12-2016 03:39 |
|
Hi Peter I'm create a Multi-Layer Gantt Chart, but I cat show the chart, could you help me please.
Thank you
Regards
seafree
|
Re: Show a Multi-Layer Gantt Chart |
Posted by Peter Kwan on Apr-13-2016 02:05 |
|
Hi seafree,
Your attached code do not seem to actually generate any chart output, as I cannot find any line that outputs the chart (no makeChart or makeTmpFile line). In Perl CGI, the charting code needs to output the chart, then the script should output HTML with an <IMG> tag that links to the chart output.
Hope this can help.
Regards
Peter Kwan |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-13-2016 04:14 |
|
Hi Peter,
You have reason Peter, I'm created the perl arrays from code Perl CGI, so I think that the array is not ok created, then the charting code not is working very well and the script shouldn't output HTML with an <IMG> tag.
Could you tell me please if the next code is ok:
my $labels=[];
my $labels_2=[];
my $startDate=[]; my $endDate=[];
my $actualstartDate=[]; my $actualendDate=[];
while($reg_reun= $sth_reun->fetchrow_hashref()){
$dates="perlchartdir::chartTime(";
$hom_reun=$reg_reun->{'homoclave'};
$f_prog=$reg_reun->{'f_prog'};
$anio_prog=substr($f_prog,0,4);
$mes_prog=substr($f_prog,5,2);
$dia_prog=substr($f_prog,8,2);
#F_PROG--------------------------------
$anio_prog.="," . $mes_prog . "," . $dia_prog;
$f_prog=$dates . $anio_prog ;
if ($contador != $registros){
$f_prog.= "),";
} else{
$f_prog.= ")";
}
push (@$startDate, $f_prog); #Etiquetas de la grafica
if ($ya_menor==0){
$anio_menor=$anio_prog;
$mes_menor=$mes_prog;
$dia_menor=$dia_prog;
$ya_menor=1;
}
if ($aux_registros == $registros){
$anio_mayor=$anio_prog;
$mes_mayor=$mes_prog;
$dia_mayor=$dia_prog;
$ya_mayor=1;
}
$aux_registros++;
#F_REAL--------------------------------
$f_real=$reg_reun->{'f_real'};
$anio_real=substr($f_real,0,4);
$mes_real=substr($f_real,5,2);
$dia_real=substr($f_real,8,2);
$anio_real.="," . $mes_real . "," . $dia_real;
$f_real=$dates . $anio_real;
if ($contador != $registros){
$f_real.= "),";
} else{
$f_real.= ")";
}
push (@$endDate, $f_real); #Etiquetas de REALIZADO
#F_RPROG--------------------------------
$f_rprog=$reg_reun->{'f_rprog'};
if ($f_rprog == 0){
$f_rprog=$dates . $anio_prog . "),";
} else{
$anio_rprog=substr($f_rprog,0,4);
$mes_rprog=substr($f_rprog,5,2);
$dia_rprog=substr($f_rprog,8,2);
$anio_rprog.="," . $mes_rprog . "," . $dia_rprog;
$f_rprog=$dates . $anio_rprog;
if ($contador != $registros){
$f_rprog.= "),";
} else{
$f_rprog.= ")";
}
$reprogramada="si";
}
push (@$actualstartDate, $f_rprog); #Etiquetas de REALIZADO
#F_RREAL--------------------------------
$f_rreal=$reg_reun->{'f_rreal'};
if ($f_rreal == 0){
$f_rreal= $f_real;
} else{
$anio_rreal=substr($f_rreal,0,4);
$mes_rreal=substr($f_rreal,5,2);
$dia_rreal=substr($f_rreal,8,2);
$anio_rreal.= "," . $mes_rreal . "," . $dia_rreal;
$dates.=$anio_rreal;
if ($contador != $registros){
$f_rreal=$dates . "),";
} else{
$f_rreal=$dates . ")";
}
push (@$actualendDate, $f_rreal); #Etiquetas de REALIZADO
}
$contador++;
} #while
Could you understand me code, please?
The array in created correctly?
Regards
seafree |
Re: Show a Multi-Layer Gantt Chart |
Posted by Peter Kwan on Apr-14-2016 00:01 |
|
Hi seafree,
It seems the dates are not created correctly. Please note that you need to call the perl function perlchartdir::chartTime to create the date. For example:
$aaa = perlchartdir::chartTime(2016, 3, 11);
Note that the following is not calling a Perl function.
$bbb = "perlchartdir::chartTime(2016, 3, 11)";
The $bbb is just a text string.
For your case, it seems $f_prog is a text string, and your code never calls perlchartdir::chartTime. If you print $f_prog, you should see "perlchartdir::chartTime(....)", which proves that it is a text string, and not Perl code. (If you print some Perl code, such as print 1 + 2 + 3;, you should see the result 6. You should not see the code "1 + 2 + 3". If you see the "Perl code", then it is not actually Perl code, but is just a text string.)
To create the date/time, my suggestion is to simply call the perlchartdir::chartTime function with the year, month and day parameters, but not to create a text string with the text "perlchartdir::chartTime".
Hope this can help.
Regards
Peter Kwan |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-16-2016 02:25 |
|
Hi Peter,
Do you have reason, I simply called the perlchartdir::chartTime function, now I must modify the code.
THANK A LOT.
Regards
seafree |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-19-2016 23:48 |
|
Hi Peter,
I copied the code of Multi-Layer Gantt Chart from ChartDirector Versión 4.1, and I changed it to code perl:
#----------------------------------------------------------------------------------------------
#!/usr/bin/perl
use v5.8.8;
use perlchartdir;
use CGI;
use CGI qw':standard *table';
use DBI;
use POSIX;
print "Content-type: text/htmlnn"; ######---Esta linea dice, que de ahà en delate todo el "print" se va a desplegar como HTML.
# the names of the tasks
my $labels = ["Market Research", "Define Specifications", "Overall Archiecture",
"Project Planning", "Detail Design", "Software Development", "Test Plan",
"Testing and QA", "User Documentation"];
# the planned start dates and end dates for the tasks
my $startDate = [perlchartdir::chartTime(2004, 8, 16), perlchartdir::chartTime(2004,
8, 30), perlchartdir::chartTime(2004, 9, 13), perlchartdir::chartTime(2004, 9, 20
), perlchartdir::chartTime(2004, 9, 27), perlchartdir::chartTime(2004, 10, 4),
perlchartdir::chartTime(2004, 10, 25), perlchartdir::chartTime(2004, 11, 1),
perlchartdir::chartTime(2004, 11, 8)];
my $endDate = [perlchartdir::chartTime(2004, 8, 30), perlchartdir::chartTime(2004, 9,
13), perlchartdir::chartTime(2004, 9, 27), perlchartdir::chartTime(2004, 10, 4),
perlchartdir::chartTime(2004, 10, 11), perlchartdir::chartTime(2004, 11, 8),
perlchartdir::chartTime(2004, 11, 8), perlchartdir::chartTime(2004, 11, 22),
perlchartdir::chartTime(2004, 11, 22)];
# the actual start dates and end dates for the tasks up to now
my $actualStartDate = [perlchartdir::chartTime(2004, 8, 16), perlchartdir::chartTime(
2004, 8, 27), perlchartdir::chartTime(2004, 9, 9), perlchartdir::chartTime(2004,
9, 18), perlchartdir::chartTime(2004, 9, 22)];
my $actualEndDate = [perlchartdir::chartTime(2004, 8, 27), perlchartdir::chartTime(
2004, 9, 9), perlchartdir::chartTime(2004, 9, 27), perlchartdir::chartTime(2004,
10, 2), perlchartdir::chartTime(2004, 10, 8)];
# Create a XYChart object of size 620 x 280 pixels. Set background color to light
# green (ccffcc) with 1 pixel 3D border effect.
my $c = new XYChart(620, 280, 0xccffcc, 0x000000, 1);
# Add a title to the chart using 15 points Times Bold Itatic font, with white
# (ffffff) text on a dark green (0x6000) background
$c->addTitle("Mutli-Layer Gantt Chart Demo", "timesbi.ttf", 15, 0xffffff
)->setBackground(0x006000);
# Set the plotarea at (140, 55) and of size 460 x 200 pixels. Use alternative
# white/grey background. Enable both horizontal and vertical grids by setting their
# colors to grey (c0c0c0). Set vertical major grid (represents month boundaries) 2
# pixels in width
$c->setPlotArea(140, 55, 460, 200, 0xffffff, 0xeeeeee, $perlchartdir::LineColor,
0xc0c0c0, 0xc0c0c0)->setGridWidth(2, 1, 1, 1);
# swap the x and y axes to create a horziontal box-whisker chart
$c->swapXY();
# Set the y-axis scale to be date scale from Aug 16, 2004 to Nov 22, 2004, with ticks
# every 7 days (1 week)
$c->yAxis()->setDateScale(perlchartdir::chartTime(2004, 8, 16),
perlchartdir::chartTime(2004, 11, 22), 86400 * 7);
# Add a red (ff0000) dash line to represent the current day
$c->yAxis()->addMark(perlchartdir::chartTime(2004, 10, 8), $c->dashLineColor(
0xff0000, $perlchartdir::DashLine));
# Set multi-style axis label formatting. Month labels are in Arial Bold font in "mmm
# d" format. Weekly labels just show the day of month and use minor tick (by using
# '-' as first character of format string).
$c->yAxis()->setMultiFormat(perlchartdir::StartOfMonthFilter(),
"<*font=arialbd.ttf*>{value|mmm d}", perlchartdir::StartOfDayFilter(),
"-{value|d}");
# Set the y-axis to shown on the top (right + swapXY = top)
$c->setYAxisOnRight();
# Set the labels on the x axis
$c->xAxis()->setLabels($labels);
# Reverse the x-axis scale so that it points downwards.
$c->xAxis()->setReverse();
# Set the horizontal ticks and grid lines to be between the bars
$c->xAxis()->setTickOffset(0.5);
# Use blue (0000aa) as the color for the planned schedule
my $plannedColor = 0x0000aa;
# Use a red hash pattern as the color for the actual dates. The pattern is created as
# a 4 x 4 bitmap defined in memory as an array of colors.
my $actualColor = $c->patternColor([0xffffff, 0xffffff, 0xffffff, 0xff0000, 0xffffff,
0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000,
0xffffff, 0xffffff, 0xffffff], 4);
# Add a box whisker layer to represent the actual dates. We add the actual dates
# layer first, so it will be the top layer.
my $actualLayer = $c->addBoxLayer($actualStartDate, $actualEndDate, $actualColor,
"Actual");
# Set the bar height to 8 pixels so they will not block the bottom bar
$actualLayer->setDataWidth(8);
# Add a box-whisker layer to represent the planned schedule date
$c->addBoxLayer($startDate, $endDate, $plannedColor, "Planned")->setBorderColor(
$perlchartdir::SameAsMainColor);
# Add a legend box on the top right corner (595, 60) of the plot area with 8 pt Arial
# Bold font. Use a semi-transparent grey (80808080) background.
my $b = $c->addLegend(595, 60, 0, "arialbd.ttf", 8);
$b->setAlignment($perlchartdir::TopRight);
$b->setBackground(0x80808080, -1, 2);
##---PREPARATIVOS PARA VISUALIZAR LA GRAFICA---##
my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");
my $imageMap = $c ->getHTMLImageMap("layergantt.pl","","title='{xLabel}:{value|0}%'");
#------------------------------------------------------------
##---CODE FOR VIEW THE CHART---##
my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");
my $imageMap = $c ->getHTMLImageMap("","","title='{xLabel}:{value|0}%'");
print <<EndOfHTML
<html>
<body bgcolor='#FFFFFF' topmargin='0' leftmargin='0'>
<div style="font-size:12pt; font-family:arial;" align="center">
<b>GRÁFICA DE GANTT
<div style="font-size:12pt; font-family:arial;" align="center"><b> PERÍODO:DEL <font color="C10434">01 de Marzo </font>AL <font color="C10434"> 31 de Marzo</font></b></div>
<center>
<img src="getchart.pl?img=/tmp/tmpcharts/$chart1URL" border="0" usemap="#map1">
<map name="map1"> $imageMap </map></center>
<table align="center" border="1" cellspacing="0">
<tr>
<td COLSPAN="4">
<center><input type=button style="font:arial; color:#ffffff; background:#639c18" value="Regresar" name="regresar" OnClick='history.back()' style='background-color:#7495ab; color:#fff;'>
</td>
</tr>
</table>
</body>
</html>
EndOfHTML
;
COULD YOU HELP ME PLEASE BECAUSE I NEITHER SHOW IT. THANKS A LOT.
Regards
Seafree |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-20-2016 01:59 |
|
Sorry Peter I can't show the chart, the chart script of curse was create the image was creates in /tmp/tmpcharts directory but it's not showed.
##-------SAVE THE IMAGE CREATED IN /tmp/tmpcharts directory------------##
my $chart1URL = $c->makeTmpFile("/tmp/tmpcharts");
my $imageMap = $c ->getHTMLImageMap("","","title='{xLabel}:{value|0}%'");
The charts image file is created, but not show:
#-----SHOW THE CHART CREATED-------#
<img src="getchart.pl?img=/tmp/tmpcharts/$chart1URL" border="0" usemap="#map1">
<map name="map1"> $imageMap </map></center>
Neither I can't show it.
I send you the complete code:
Thanks a lot Peter, I don't found the mistake.
Sorry I'm terrific.
|
Re: Show a Multi-Layer Gantt Chart |
Posted by Peter Kwan on Apr-20-2016 05:09 |
|
Hi seafree,
I have just tried your code, with some minor modification to fit my Perl installation (removing the using CGI, DB and POSIX lines), and it works normally.
If the chart is successfully created in /tmp/tmpcharts, but you cannot see the chart, it is likely to be because the HTML is incorrect, or the path is incorrect.
You probably are aware that to see the chart image, you need an <IMG> tag, and in your code, the tag is <img src="getchart.pl?img=/tmp/tmpcharts/$chart1URL" ....>. So the tag uses "getchart.pl". Have you put the "getchart.pl" in the same directory as your script, so that the above path is correct? If you put the "getchart.pl" in some other directories, please make sure you adjust the path to allow the <IMG> tag to load the image.
If the above still does not solve the problem, would you mind to clarify what do you see on the screen? Do you see the "Regresar" button in your code, which the confirms the HTML is correct? If you do not see the image, do you see a broken image symbol, which is something like a "red X" in some browser? If you see a broken image symbol, please go into the symbol to get the error message. See:
http://www.chartdir.com/forum/download_thread.php?site=chartdir&bn=chartdir_faq&thread=1117817200
Please let me know what is the result.
Regards
Peter Kwan |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-20-2016 23:08 |
|
Hi Peter,
THANKS A LOT, my cgi program works correctly.
You had reason I'm aware how to see the chart image in HTML, but I didn't use correct HTML code, I modified it then all is correct, I can see the chart.
-----------------------
print "Content-type: text/htmlnn";
print <<EndOfHTML
<html>
<body bgcolor='#FFFFFF' topmargin='0' leftmargin='0'>
<div style="font-size:12pt; font-family:arial;" align="center">
<b>GRÁFICA DE GANTT</b>
</div>
<div style="font-size:12pt; font-family:arial;" align="center"><b> PERÍODO:DEL <font color="C10434">01 de Marzo </font>AL <font color="C10434"> 31 de Marzo</b></font></div>
<center>
<img src="getchart.pl?img=/tmp/tmpcharts/$chart1URL" border="0" usemap="#map1">
<map name="map1">$imageMap</map></center>
</body>
</html>
EndOfHTML
;
-------------------------
You are a great guru.
Regards
seafree |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-23-2016 02:02 |
|
Hi Peter,
After my last message, I continued working with my gantt program, now this access to database for fill arrays:
my $aref_labels=[],
my $aref_startDate=[],
my $aref_endDate=[],
my $aref_actualstartDate=[] and
my $aref_actualendDate=[].
So I used this datatable for fill the arrays, file created with sql statement:
data_gant.csv
And thi's my program, but I can't see data drawed only it show the charts with labels but no data.
grafica_gantPR.pl
I attach the files that I mention above.
Could you help me Peter, please.
Thanks a lot
Regards
Seafree
|
Re: Show a Multi-Layer Gantt Chart |
Posted by Peter Kwan on Apr-26-2016 01:12 |
|
Hi seafree,
If the chart works hard coded data, but does not work with the data your code retrieved from the database, please check that your code reads the data correctly. You may want to print the data arrays out to verify if they are correct. For example:
print "Scale = $anio_menor - $mes_menor - $dia_menor to $anio_mayor - $mes_mayor - $dia_mayor <br>";
print "Actual <br>";
for (my $i = 0; $i < scalar(@$aref_actualstartDate); ++$i) {
print perlchartdir::getChartYMD($aref_actualstartDate->[$i]) . " to" . perlchartdir::getChartYMD($aref_actualendDate->[$i]) . "<br>";
}
print "Planned <br>";
for (my $i = 0; $i < scalar(@$aref_startDate); ++$i) {
print perlchartdir::getChartYMD($aref_startDate->[$i]) . " to" . perlchartdir::getChartYMD($aref_endDate->[$i]) . "<br>";
}
Also, I think the $actualColor in your code is set incorrectly. May be you can use the original $actualColor or set it to a solid color (like 0x888888) for testing.
Regards
Peter Kwan |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-26-2016 23:33 |
|
Hi Peter,
I printed the data arrays out to verify if they are correct, and the result was. There are 3 rows:
ROW 1:
PROGRAMADO: push (aref_startDate, 63593251200); #Label Programmer
REALIZADO: push (aref_endDate, 63593251200); #Label Real
F_RPROG PARAMETER:
ROW 2:
PROGRAMADO: push (aref_startDate, 63593683200); #Label Programmer
REALIZADO: push (aref_endDate, 63593683200); #Label Real
F_RPROG PARAMETER:
ROW 3:
PROGRAMADO: push (aref_startDate, 63594115200); #Label Programmer
REALIZADO: push (aref_endDate, 63594115200); #Label Real
F_RPROG PARAMETER: 2016-03-23 08:00:00
push (aref_actualstartDate, 63594288000); #Label Reprogrammer
REREALIZADO==: push (aref_actualendDate, 63594288000);; #Label actualendDate
Scale = 2016 - 03 - 11 to 2016 - 03 - 21
Actual
for (my = 0; < scalar(63594288000); ++) {
print " perlchartdir::getChartYMD(63594288000) . ' to ' . perlchAartdir::getChartYMD(63594288000) ";
20160323 to 20160323
Planned
20160311 to 20160311
20160316 to 20160316
20160321 to 20160321
3 rows Planned and 1 Reprogrammer (Actual), is it correct?
I used the original $actualColor like you told me:
my $actualColor = $c->patternColor([0xffffff, 0xffffff, 0xffffff, 0xff0000, 0xffffff,
0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000, 0xffffff, 0xffffff, 0xff0000,
0xffffff, 0xffffff, 0xffffff], 4);
And this:
#Add a box whisker layer to represent the actual dates. We add the actual dates
# layer first, so it will be the top layer.
my $actualLayer = $c->addBoxLayer($aref_actualstartDate, $aref_actualendDate, $actualColor, "Actual");
Also, I used the original $actualColor and set it to a solid color (0x888888), but it does not work with the data retrieved from the database.
I send you the image, that the code is created.
I hope you can help me, and I hope you can understand me report.
Regards
seafree
|
Re: Show a Multi-Layer Gantt Chart |
Posted by Peter Kwan on Apr-27-2016 00:06 |
|
Hi seafree,
If your data are correct, then it seems the chart is correct too. It accurately plots your data.
All of the bars should have zero length, as the starting date/time and ending date/time are exactly the same. They should just be a thin line.
The bar at 20160323 to 20160323 is obviously not visible because your axis scale is only up to 2016-03-21.
The bar at 20160311 to 20160311 and 20160321 to 20160321 should not be visible. As your axis scale is 2016 - 03 - 11 to 2016 - 03 - 21, these two bars are at the end points of the axis scale, and they are just a thin line, and so they are covered by the axis or plot area border.
The 20160316 to 20160316 bar should be visible as a thin line, and the chart does show the thin line.
If the chart is not what you expect, is it possible your data are not correct? For example, the starting date/time and ending date/time may not be the same, and the axis scale should include all the bars.
Regards
Peter Kwan |
Re: Show a Multi-Layer Gantt Chart |
Posted by seafree on Apr-27-2016 01:22 |
|
Hi Peter you are grandiose!, you had reason about you response, thaks a lot.
Regards
Seafree |
|