pChart 2.x forum
http://wiki.pchart.net/forum/

AXIS_FORMAT_DURATION
http://wiki.pchart.net/forum/viewtopic.php?f=4&t=471
Page 1 of 1

Author:  tr0nix [ Wed Jun 01, 2011 1:28 pm ]
Post subject:  AXIS_FORMAT_DURATION

Hi there

I felt in the pitfall, that AXIS_FORMAT_TIME is not meant to be a duration measurement but a 24h clock measure. So because I record runtime durations of tasks (hh:mm:ss), this was not suitable because they may exceed 24h and the am/pm format is also not suitable.

Now here comes the hack:

pData.class.php (add to the axis configuration starting at line 16:
define("AXIS_FORMAT_DURATION", 680006);

pDraw.class.php (add to the scaleFormat function starting at line 2765):
if ( $Mode == AXIS_FORMAT_DURATION ) {
$hours = floor($Value / 3600);
$Value -= $hours * 3600;
$minutes = floor($Value / 60);
$seconds = $Value % 60;
return (sprintf("%d:%02d:%02d", $hours, $minutes, $seconds));
}


Formatting is not supported in this hack, however it's quiet easy changeable until it may get it's way into the official code. Just modify the sprintf feedback to the calling function. Remember that the dataset must be given in seconds.

@Jean-Damien: The way these axis formats can be modified is so easy, really good work! It took me maybe 20 minutes to do the hack without having ever been working with pChart before. Just one thing - can you loose some words on the "minDivHeight" and "Factors" parameter for drawScale?

Oh.. and one more thing.. I downloaded pchart as zip file but in reality it was a .zip.gz (therefore I had to gunzip first and unzip afterwards). Maybe u should fix that...

Regards
Joel

Attachments:
durationchart.png
durationchart.png [ 14.44 KiB | Viewed 13761 times ]

Author:  ijazz [ Thu Jul 28, 2011 10:41 pm ]
Post subject:  Re: AXIS_FORMAT_DURATION

I figure out now about the Factors parameter. It's an array that stands for the minor unit for Y-Axis and represents how many subdivisions the scale can have, depending on the max and mix axis values.

Code:
$settings = array("Factors"=>array(1,2));
$pic->drawScale($settings);

The code above sets the minor unit for one or half, as 0---0.5---1---1.5---2---2.5---3.

Code:
$settings = array("Factors"=>array(1));
$pic->drawScale($settings);

The code above sets the minor unit for one , as 0---1---2---3...

I hope it helps!

Author:  jean-damien [ Sun Jul 31, 2011 8:13 am ]
Post subject:  Re: AXIS_FORMAT_DURATION

Good idea! I'll add this new format in the next sub release.

Thanks for your help ;o)

Kind regards,
JD.

Author:  Magg45 [ Mon Jul 08, 2013 4:43 am ]
Post subject:  Re: AXIS_FORMAT_DURATION

public static void main(String[] args) {
Duration dur = new Duration();
dur.setHours(17);
dur.setMinutes(30);

SimpleDateFormat simpDate = new SimpleDateFormat("kk:mm");
System.out.println(simpDate.format(dur.getAsCalendar().getTime()));




I need to know from you dude. Id thids ok to use above format I required HH:mm but didn't.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/