View unanswered posts | View active topics It is currently Thu May 09, 2024 6:46 am



Reply to topic  [ 7 posts ] 
How to not draw line when value is VOID or 0 
Author Message
pChart user
pChart user

Joined: Tue Mar 15, 2011 8:54 am
Posts: 7
Post How to not draw line when value is VOID or 0
Thank you for a wonderful charting class.

I have a line chart that is "live" i.e., it's updated constantly. One of the problems currently is that during the day I want to stop drawing the line if I don't yet have a value. I have mainly modified the examples and my experiments from the sandbox, so it's possible I have overridden some default value that would do what I wanted. I can give the full source if needed.

So in the morning I don't have values for the afternoon so the line should stop to whatever the last value is.
The first image is an unfinished chart. So the line should end at 8.45 (and not start before 6 o'clock as there's no values).
Attachment:
day_should_cut.jpg
day_should_cut.jpg [ 14.84 KiB | Viewed 12610 times ]


The 2nd chart shows how how the line continues even though the values are empty or zero.
Attachment:
day_notok.jpg
day_notok.jpg [ 19.92 KiB | Viewed 12610 times ]


This graph shows how the chart should look like when all the values have been set, but the line is not drawn if the value is 0 or empty.

Attachment:
day_ok.jpg
day_ok.jpg [ 41.96 KiB | Viewed 12610 times ]


I'm pretty sure there's a way to do it, but I just don't seem to find the correct setting.

Another problem currently is that I can't seem to format the time values (x-axis) without setting abscissa to it ("lundi 14 mars" in the second image)

I use (or have to use) the following in my code:

$myData->addPoints($time, $bottom_label);
$myData->setAbscissa($bottom_label);

If left off, the values for x-axis are just plain numbers instead of time values.

SO the question is how can I format the x-axis values so that I don't get the label below it but still get correct time values on the axis.


Tue Mar 15, 2011 10:17 am
Profile
Regular pChart user
Regular pChart user

Joined: Sun Mar 06, 2011 3:07 pm
Posts: 15
Post Re: How to not draw line when value is VOID or 0
Hi nrde,

the way to do it is to set the data points to VOID:
$data1[] = VOID;

Note that VOID is not in quotes but written like a parameter (I fell for it and wondering why VOID doesn't work).

Next thing to do is make sure that BreakVoid is NOT set to FALSE. It should be set to TRUE on default. So search if BreakVoid is appearing or set to FALSE anywhere in your code.
Also check this tutorial: http://wiki.pchart.net/doc.missing.points.html

That should do it.

For your second point, I am not sure how to disable the labels. I looked for it but then found this workaround: I moved the axis so far down so you cant see the label :)


Tue Mar 15, 2011 1:40 pm
Profile
pChart user
pChart user

Joined: Tue Mar 15, 2011 8:54 am
Posts: 7
Post Re: How to not draw line when value is VOID or 0
bluhm wrote:
the way to do it is to set the data points to VOID:
$data1[] = VOID;


yes, I already have something like this:
Code:
      if($val[1] == "" || $val[1] == null || $val[1] == 0){
         
         $value[] = VOID;
         
      } else {
         
         $value[] = $val[1];
      }


I can verify that the array really has VOID in it.

UPDATE: if I manually assign array(1,2,VOID, 10,4,etc...) to the series I see the gaps in the line, but if I do it dynamically like in my code above the "VOID" is not recognized. Does anyone have a working example how to dynamically build an array and the "VOID" values recognized?

Quote:
Next thing to do is make sure that BreakVoid is NOT set to FALSE. It should be set to TRUE on default. So search if BreakVoid is appearing or set to FALSE anywhere in your code.
Also check this tutorial: http://wiki.pchart.net/doc.missing.points.html


Yes, I found that setting from the documentation, but could not get it to work and thought there's something special to it. But even specifically setting it to TRUE, it still does not work.

I'll try to set the value to the magic number next.


Wed Mar 16, 2011 7:46 am
Profile
Regular pChart user
Regular pChart user

Joined: Sun Mar 06, 2011 3:07 pm
Posts: 15
Post Re: How to not draw line when value is VOID or 0
Hi,

this one is working. It is a bit more complex because of double loops.

Code:
while ($reportrow = mysql_fetch_array($reports)) {
        $report = $reportrow["reportname"];
        $buydata[$report][] = VOID;
        $selldata[$report][] = VOID;
        $signalsql = "SQL FILTERED OUT";
        $result  = mysql_query($signalsql);
        while ($row = mysql_fetch_array($result)) {
                $closevalue = $row["close"];
                if( $row["ordertype"] == "B" ) { $buydata[$report][] = $closevalue; } else { $buydata[$report][] = VOID; }
                if( $row["ordertype"] == "S" ) { $selldata[$report][] = $closevalue; } else { $selldata[$report][] = VOID; }
        }
        $MyData->addPoints($selldata[$report], "S".$report);
        $MyData->addPoints($buydata[$report], "B".$report);
}


not using any breakvoid in my code at all. Maybe post your assignment code so I can have a look at it.

Best wishes,

Stefan


Wed Mar 16, 2011 12:55 pm
Profile
pChart user
pChart user

Joined: Tue Mar 15, 2011 8:54 am
Posts: 7
Post Re: How to not draw line when value is VOID or 0
Hi, thanks for your help. Here's the code I'm using.

Code:
      if($val[1] == "" || $val[1] == null || $val[1] == 0 || $val[1] == "0"){
         
         $value[] = VOID;
         
      } else {
         
         $value[] = $val[1];
         
      }

$myData = new pData();

// continuos line
$myData->addPoints($value,"Serie1");

// breaking line
//$myData->addPoints(array(2,3,4,VOID,5,10,15,VOID,VOID,VOID,10,14,17,22,"Serie1"));
...
$Config = array("BreakVoid"=>TRUE);
$myPicture->drawLineChart($Config);


So as you see, there's nothing special. Only thing that comes to mind is that the class doesn't recognize my "VOIDS" being "VOIDS", but I don't know how that could be the case.


Wed Mar 16, 2011 1:13 pm
Profile
pChart user
pChart user

Joined: Tue Mar 15, 2011 8:54 am
Posts: 7
Post Re: How to not draw line when value is VOID or 0
Ok, stupid me...

I included the pdata class file after I constructed the array, so the VOID constant wasn't defined yet.

Everything is now working when I included the pdata class before I started to use VOID :)


Wed Mar 16, 2011 1:29 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: How to not draw line when value is VOID or 0
Hi,

That is correct, the VOID constant is declared in the pData class. I'm using it as the NULL value is equal to 0 which cause the issues you may imagine..

Kind regards,
JD.


Wed Mar 23, 2011 10:48 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 7 posts ] 

Who is online

Users browsing this forum: No registered users and 17 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