Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3990866
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:32:46+00:00 2026-05-20T06:32:46+00:00

Could anybody explain why I am able to display a php graph when I

  • 0

Could anybody explain why I am able to display a php graph when I use the code below only in a php file but, when in a php file with additional code, control characters print instead of the graph?

function display_graph() {
//begin graph
//  # ------- The graph values in the form of associative array
    $values=array(
        "Jan" => 110,
        "Feb" => 130,
        "Mar" => 215,
        "Apr" => 81,
        "May" => 310,
        "Jun" => 110,
        "Jul" => 190,
        "Aug" => 175,
        "Sep" => 390,
        "Oct" => 286,
        "Nov" => 150,
        "Dec" => 196
    );
            $img_width=450;
            $img_height=300; 
            $margins=20;
//  # ---- Find the size of graph by substracting the size of borders
            $graph_width=$img_width - $margins * 2;
            $graph_height=$img_height - $margins * 2; 
            $img=imagecreate($img_width,$img_height);
            $bar_width=20;
            $total_bars=count($values);
            $gap= ($graph_width- $total_bars * $bar_width ) / ($total_bars +1);
//  # -------  Define Colors ----------------
            $bar_color=imagecolorallocate($img,0,64,128);
            $background_color=imagecolorallocate($img,240,240,255);
            $border_color=imagecolorallocate($img,200,200,200);
            $line_color=imagecolorallocate($img,220,220,220);
//  # ------ Create the border around the graph ------
            imagefilledrectangle($img,1,1,$img_width-2,$img_height-2,$border_color);
            imagefilledrectangle($img,$margins,$margins,$img_width-1-$margins,$img_height-1-$margins,$background_color);
//  # ------- Max value is required to adjust the scale -------
            $max_value=max($values);
            $ratio= $graph_height/$max_value;
//  # -------- Create scale and draw horizontal lines  --------
            $horizontal_lines=20;
            $horizontal_gap=$graph_height/$horizontal_lines;
            for($i=1;$i<=$horizontal_lines;$i++){
                $y=$img_height - $margins - $horizontal_gap * $i ;
                imageline($img,$margins,$y,$img_width-$margins,$y,$line_color);
                $v=intval($horizontal_gap * $i /$ratio);
                imagestring($img,0,5,$y-5,$v,$bar_color);
            } 
//  # ----------- Draw the bars here ------
            for($i=0;$i< $total_bars; $i++){ 
                # ------ Extract key and value pair from the current pointer position
                list($key,$value)=each($values); 
                $x1= $margins + $gap + $i * ($gap+$bar_width) ;
                $x2= $x1 + $bar_width; 
                $y1=$margins +$graph_height- intval($value * $ratio) ;
                $y2=$img_height-$margins;
                imagestring($img,0,$x1+3,$y1-10,$value,$bar_color);
                imagestring($img,0,$x1+3,$img_height-15,$key,$bar_color);       
                imagefilledrectangle($img,$x1,$y1,$x2,$y2,$bar_color);
            }
            //header("Content-type:image/png");
            imagepng($img);
            imagepng($img);
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:32:47+00:00Added an answer on May 20, 2026 at 6:32 am

    In order to work your additional code should not send data on the standard output.
    Even a single space could corrupt your image. If the image is corrupted it not fit with the Content-Type and the browser not display the image but its binary code.

    Check things like , print , echo …, in your additonal code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code prints out MyUrgentException . Could anybody explain why? class MyException extends Exception{
Could anybody explain what's the problem with listeners in this code? I just started
Could anybody explain in plain words how Cloud computing works? I have read the
Could anybody explain what is the cause of the following: >>> from M2Crypto import
Could anybody explain to me the process of uploading to and downloading form and
Can anybody please explain how this could possibly happen? I am completely aware of
Could anybody brief about user_token functionality in Auth module? What is a use and
Could anybody explain why the static property is null? class Program { static void
Could anybody explain me what's the difference with setactivewindow with setforegroundwindow (using pinvoke from
I am new to ruby on rails, could anybody explain what does the symbol

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.