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

Datetime at irregular intervals
http://wiki.pchart.net/forum/viewtopic.php?f=1&t=173
Page 1 of 2

Author:  lukasr [ Fri Feb 04, 2011 2:35 pm ]
Post subject:  Datetime at irregular intervals

First of all thanks for the very good chart Library!

I had the problem that I wanted to display a datetime series on the x axis which had irregular intervals. But the current version of pChart doesn't seem to support this way of scaling.
Attachment:
File comment: current
test_current_02.png
test_current_02.png [ 14.99 KiB | Viewed 34068 times ]


I expected it to look like this:
Attachment:
File comment: expected
test_expected_02.png
test_expected_02.png [ 13.26 KiB | Viewed 34068 times ]


I've just added the necessary functionality to auto scale to the drawScale, the drawStepChart and the drawFilledStepChart functions - more will come soon.
Find the unified diff file for pChart 2.1.0 attached.

It also adds the functionality to display lines in regular intervals:
Attachment:
File comment: current_lines
test_current_02_lines.png
test_current_02_lines.png [ 23.95 KiB | Viewed 34068 times ]


I hope you'll find it useful.

Author:  lukasr [ Fri Feb 04, 2011 2:38 pm ]
Post subject:  Re: Datetime at irregular intervals

Here is the attachment...

Attachment:
File comment: unified diff
pDraw.class.php_2.1.0.diff.zip [3.63 KiB]
Downloaded 1869 times

Author:  jean-damien [ Fri Feb 04, 2011 2:42 pm ]
Post subject:  Re: Datetime at irregular intervals

I really like this, I'll dig into it to integrate what's missing.

Thank you ;o)

Author:  lukasr [ Fri Feb 04, 2011 3:00 pm ]
Post subject:  Re: Datetime at irregular intervals

Here is also some sample code (based on the stepchart example):

Code:
<?php   
/* CAT:Step chart */

/* pChart library inclusions */
include("../class/pData.class.php");
include("../class/pDraw.class.php");
include("../class/pImage.class.php");

/* Create and populate the pData object */
$MyData = new pData(); 
$MyData->addPoints(array(-4,VOID,VOID,12,8,3),"Probe 1");
$MyData->addPoints(array(3,12,15,8,5,-5),"Probe 2");
$MyData->addPoints(array(2,7,5,18,19,22),"Probe 3");
$MyData->setSerieTicks("Probe 2",4);
$MyData->setAxisName(0,"Temperatures");
$MyData->addPoints(array(1296299019,1296302903,1296307001,1296308071,1296309901,1296318931),"Labels");
$MyData->setSerieDescription("Labels","Timestamp");
$MyData->setXAxisDisplay(AXIS_FORMAT_DATE,"H:i");
$MyData->setAbscissa("Labels");

/* Create the pChart object */
$myPicture = new pImage(700,230,$MyData);

/* Draw the background */
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,700,230,$Settings);

/* Overlay with a gradient */
$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,700,230,DIRECTION_VERTICAL,$Settings);
$myPicture->drawGradientArea(0,0,700,20,DIRECTION_VERTICAL,array("StartR"=>0,"StartG"=>0,"StartB"=>0,"EndR"=>50,"EndG"=>50,"EndB"=>50,"Alpha"=>80));

/* Add a border to the picture */
$myPicture->drawRectangle(0,0,699,229,array("R"=>0,"G"=>0,"B"=>0));

/* Write the picture title */
$myPicture->setFontProperties(array("FontName"=>"../fonts/Silkscreen.ttf","FontSize"=>6));
$myPicture->drawText(10,13,"drawStepChart() - draw a step chart",array("R"=>255,"G"=>255,"B"=>255));

/* Write the chart title */
$myPicture->setFontProperties(array("FontName"=>"../fonts/Forgotte.ttf","FontSize"=>11));
$myPicture->drawText(250,55,"Average temperature",array("FontSize"=>20,"Align"=>TEXT_ALIGN_BOTTOMMIDDLE));

/* Draw the scale and the 1st chart */
$myPicture->setGraphArea(60,60,450,190);
$myPicture->drawFilledRectangle(60,60,450,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale(array("DrawSubTicks"=>TRUE,"LabelShowBoundaries"=>TRUE,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->setFontProperties(array("FontName"=>"../fonts/pf_arma_five.ttf","FontSize"=>6));
$myPicture->drawStepChart(array("DisplayValues"=>TRUE,"DisplayColor"=>DISPLAY_AUTO,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(FALSE);

/* Draw the scale and the 2nd chart */
$myPicture->setGraphArea(500,60,670,190);
$myPicture->drawFilledRectangle(500,60,670,190,array("R"=>255,"G"=>255,"B"=>255,"Surrounding"=>-200,"Alpha"=>10));
$myPicture->drawScale(array("Pos"=>SCALE_POS_TOPBOTTOM,"DrawSubTicks"=>TRUE,"ScaleModeAuto"=>TRUE));
$myPicture->setShadow(TRUE,array("X"=>-1,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
$myPicture->drawStepChart(array("ScaleModeAuto"=>TRUE));
$myPicture->setShadow(FALSE);

/* Write the chart legend */
$myPicture->drawLegend(510,205,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_HORIZONTAL));

/* Render the picture (choose the best way) */
$myPicture->autoOutput("pictures/example.drawStepChart.png");
?>


Result:
Attachment:
File comment: step chart auto scale
example.drawStepChartAutoScale.png
example.drawStepChartAutoScale.png [ 30.38 KiB | Viewed 34060 times ]

Author:  sidkdbl07 [ Tue Feb 08, 2011 12:24 am ]
Post subject:  Re: Datetime at irregular intervals

jean-damien wrote:
I really like this, I'll dig into it to integrate what's missing.

Thank you ;o)


Jean-damien,

Does this mean we can expect the datetime x-axis to work this way from now on? The improper spacing of datetime scales has been one of my biggest compliants about this library.

I don't mean to complain too much. This is a fantastic project and I use your library with a lot of respect for you Jean-damien

Author:  jean-damien [ Tue Feb 08, 2011 8:39 am ]
Post subject:  Re: Datetime at irregular intervals

Hi,

I'm thinking on how to get it implemented yes. My guess is that non-linear X scales will be implemented directly withing the current scaling methods. This will force a rewritting of some part of the scaling and charting functions --nothing too complicated hopefully.

I can't promise it for the next sub release but it will come in the following one.

Kind regards,
JD.

Author:  rizaldi [ Tue Aug 02, 2011 9:51 am ]
Post subject:  Re: Datetime at irregular intervals

hi lukasr, what is the right way to apply the patch? i try to do this

Code:
patch < pDraw.class.php_2.1.0.diff


but i always get error messages saying hunk failed. Thanks before :)

update : silly of me :lol: , all of the problem because the file is dos type

Author:  form [ Mon Oct 24, 2011 7:33 pm ]
Post subject:  Re: Datetime at irregular intervals

Hi,
is the patch already included in newer versions?
Is it possible for DrawLineChart, also?

Regards
form

Author:  danielmauch [ Fri Nov 11, 2011 1:53 pm ]
Post subject:  Re: Datetime at irregular intervals

I would need this as well - ;-)

Author:  pawnies20 [ Thu Jul 12, 2012 7:53 am ]
Post subject:  Re: Datetime at irregular intervals

Hi !!!
Same problem!

Is newest version integer this capabiliies?

THNAX

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