Jump to content

PHP GD Image Graphing problem with color running out


akphidelt2007

Recommended Posts

Ok, I have a graphing class that I built to build simple bar/line graphs for work. I have a side project I'm working on that is a little bigger in terms of data. Usually I do months or weeks. But I have some arrays with about 1000 data sets.

 

And when I create the image it stops at a certain point and doesn't even draw the X-Axis (One of the last procedures in my code).

 

And I know there is an issue, because if I Limit the query to 100 results, the graph will come out fine. If I limit it to 200 results the plotted line will show but the X-Axis will be cut of. If I put it to 300 results the plotted line will stop towards 2/3rds the way through the graph.

 

So I know the code is working when I reduce the results. I check the image info and it's only 3.25kb in size. Not sure what's going on here. I tried googling it but really didn't come up with any solid answers like most google searches.

 

If anyone has a clue why this is happening, please let me know.

 

Thanks a lot in advance.

 

And what's weird is if I add Zebra gridlines to it, on the colored zebra background, I can see a white line that represents the data. It's almost like the ink runs out, lol.

Edited by akphidelt2007
Link to comment
Share on other sites

cannot really help you without seeing the offending code, but if you are passing this data through the url to the dynamic image creation php code, it's likely due to the maximum length permitted for urls or the maximum number of $_GET variables that some servers/php (hardened php patch) imposes.

Edited by mac_gyver
Link to comment
Share on other sites

cannot really help you without seeing the offending code, but if you are passing this data through the url to the dynamic image creation php code, it's likely due to the maximum length permitted for urls or the maximum number of $_GET variables that some servers/php imposes.

 

Problem is, if I post the code it's my own graphing class so it doesn't make any sense. It basically stops "drawing" the graph at the last point.

 

for instance...

function DrawGraph()
{
    $this->__IMG = imagecreate($this->img->width,$this->img->height) or die("No Library");
    
    $this->DrawImgBG();
    $this->DrawImgBorder();
    $this->DrawTitle();
    $this->DrawY1Axis();
    $this->DrawGridlines();
    $this->Plotter();
    $this->DrawXAxisBorder();
    $this->DrawXAxis();
    $this->DrawLegend();
    $this->DrawGraphBG();
    $this->DrawGraphBorder();    
}

Not passing any data through a url. So the last items to be "drawn" are what disappear as I increase the limit size. So everything is proportional. When I don't have a limit the plotted line stops at the right coordinates... I've checked through the math of the plotter, and the data that is not showing up shows the right coordinates for where it should be. The color just doesn't show up. And if I reduce the limit to say 100, the entire graph shows perfectly. 200, I start to lose most of the x axis, although the ticks and labels are showing up in their right coordinates. If I move the limit to 300, the entire x-axis doesn't show up, and I start losing visibility at the end of the plotted line. I don't think it's a coding part in terms of drawing the graph. I think it might be something in terms of how I'm displaying it. I don't do anything fancy. Here is how I display the graph...

 

Edit:: And by limit size, I'm simply talking about putting a LIMIT on the query.

function Display()
{
    //first step is to calculate the YAxis and figure out the dimensions
    $this->ScrubData();
    
    $this->DrawGraph();
    
    $path = $this->imgPath ? $this->imgPath : "image.png";
    imagepng($this->__IMG,$path);
    imagedestroy($this->__IMG);
    
    return "<img src='$path?num=" . time() . "'>"; exit;
}
Edited by akphidelt2007
Link to comment
Share on other sites

Here's an example with a LIMIT set to 200... if you look very closely you can see the line is still being drawn at the correct coordinates, it's just "running out of color"... not sure what the correctly terminology is. I created 2 lines here, where the 2nd line is just the first set of data - 10. If I switch it to 100, the whole graph shows up correctly.

 

image.png

Link to comment
Share on other sites

the problem's either in -

 

1) the actual data values. perhaps something (number format or magnitude) about the specific data in the 200-300 range is causing a calculation problem...

 

2) the length/amount of data. perhaps some of the calculations/scaling is wrapping round and overwriting values...

 

3) perhaps the data is actually being written to the image but the color being used got changed (i would be logging to a file the actual data that the program is using when it calls the gd functions to try and pin down the problem.)

 

4) could be a php bug in the gd functions, but in about 99.8% of cases where code doesn't do what you expect, the problem is in the code.

Edited by mac_gyver
Link to comment
Share on other sites

Still can't figure it out. I echoed out the code that the function I use to draw the lines is using and it comes out with the right coordinates, right color, and everything else. It's just weird you can see the line being drawn in "white" if you look closely. And any color I try does the same thing at the same spot.

 

To me this has to be some kind of memory or size limit issue. I can't find it through googling either. Very frustrating.

Link to comment
Share on other sites

since colors in the gd function calls are actually color identifiers for that specific image resource, i would guess your normal color identifier (black) is being redefined/overwritten as (white.)

 

again, these are just educated guesses/general troubleshooting tips since i/we are not there in the room with you and only see the information you have supplied in this thread.

 

in fact, the only thing i can definitely tell you about your code is, in the display() method, the exit; statement after the return statement doesn't do anything since the return statement ends execution of that method's code.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.