View unanswered posts | View active topics It is currently Sat Apr 13, 2024 7:09 pm



Reply to topic  [ 5 posts ] 
drawVerticalLine 
Author Message
Regular pChart user
Regular pChart user

Joined: Wed Jun 01, 2011 11:42 am
Posts: 9
Post drawVerticalLine
Add to pDraw.class.php:
Code:
function drawVerticalLine($SeriesName, $Index, $Format="") {
   $VerticalLineR      = isset($Format["VerticalLineR"]) ? $Format["VerticalLineR"] : 0;
   $VerticalLineG      = isset($Format["VerticalLineG"]) ? $Format["VerticalLineG"] : 0;   
   $VerticalLineB      = isset($Format["VerticalLineB"]) ? $Format["VerticalLineB"] : 0;   
   $VerticalLineAlpha   = isset($Format["VerticalLineAlpha"]) ? $Format["VerticalLineAlpha"] : 40;
   $VerticalLineTicks   = isset($Format["VerticalLineTicks"]) ? $Format["VerticalLineTicks"] : 2;

   $Data = $this->DataSet->getData();
   list($XMargin,$XDivs) = $this->scaleGetXSettings();
   if ( $XDivs == 0 ) { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1)/4; } else { $XStep = ($this->GraphAreaX2-$this->GraphAreaX1-$XMargin*2)/$XDivs; }
   $X = $this->GraphAreaX1 + $XMargin + $Index * $XStep;

   $this->drawLine(
      $X,
      $this->GraphAreaY1 + $Data["YMargin"],
      $X,
      $this->GraphAreaY2-$Data["YMargin"],
      array("R"=>$VerticalLineR,"G"=>$VerticalLineG,"B"=>$VerticalLineB,"Alpha"=>$VerticalLineAlpha,"Ticks"=>$VerticalLineTicks)
   );
}


Now if you have an Y-Date-Axis and you want to put a vertical line on each Friday and Monday (to separate Saturday and Sunday), just go like this:
Code:
      foreach($this->pChartData->getValues("Date") as $index => $date) {
         $dateSplit = preg_split ('/\./', $date); /* this depends on your format.. mine is DD.MM.YYYY */
         $weekDay = date('N', mktime(0, 0, 0, (int)$dateSplit[1], (int)$dateSplit[0], (int)$dateSplit[2]));

         if ( $weekDay == 5 | $weekDay == 1) {
            $this->pChart->drawVerticalLine("Date", $index, $LabelSettings);
         }
      }


Will look like attached (in combination with "BreakVoid"=>FALSE format for drawLineChart)..


Attachments:
pcharttest.png
pcharttest.png [ 58.65 KiB | Viewed 11837 times ]
Fri Jun 24, 2011 3:58 pm
Profile
Regular pChart user
Regular pChart user

Joined: Wed Jun 01, 2011 11:42 am
Posts: 9
Post Re: drawVerticalLine
As soon as you can get the real x/y coordinates of the dataset-values this function can be replaced with drawline which will be more stable for sure :-)!


Fri Jun 24, 2011 4:11 pm
Profile
Regular pChart user
Regular pChart user

Joined: Sun Aug 14, 2011 3:34 pm
Posts: 8
Post Re: drawVerticalLine
Nice looking graph!

_________________
Random Facts Little Known Facts


Sat Sep 10, 2011 2:28 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: drawVerticalLine
Hi,

I've added the drawXThreshold() function in the 2.1.3 subversion. When called this function return the X position of the vertical threshold that you can re-use for further processing. (same applies for the Y thresholds an areas)

JD.


Mon Sep 12, 2011 7:09 am
Profile WWW
Regular pChart user
Regular pChart user

Joined: Wed Jun 01, 2011 11:42 am
Posts: 9
Post Re: drawVerticalLine
:mrgreen: cool!


Fri Oct 07, 2011 1:21 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron