working with jpgraph

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    working with jpgraph

    im using jp graph and i want to put a graph code at the middle of my table. Then I got error:
    JpGraph Error: HTTP headers have already been sent.
    Caused by output from file test.php at line 2.
    Explanation:
    HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).

    Most likely you have some text in your script before the call to Graph::Stroke() . If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser.

    For example it is a common mistake to leave a blank line before the opening "<?php".


    Could anyone tell me how can i solve that?
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    I'm confused? Did u check the top of the page where it says <?php ? Straight after the word php, if there is a space (black character) you will have a problem. That's what your post says, so you would already know that. Can you post the codefor the jpgraph? If it's too big, post your page code (mainly where your header is) and then have a look in the jpgraph code for the word header and post surrounding code for that.

    Comment

    • ghjk
      Contributor
      • Jan 2008
      • 250

      #3
      Originally posted by TheServant
      I'm confused? Did u check the top of the page where it says <?php ? Straight after the word php, if there is a space (black character) you will have a problem. That's what your post says, so you would already know that. Can you post the codefor the jpgraph? If it's too big, post your page code (mainly where your header is) and then have a look in the jpgraph code for the word header and post surrounding code for that.
      Thanks for your reply. This is my graph code and this is working.
      [PHP]
      <?php
      include ("../rainfall_ITI/jpgraph2.3/src/jpgraph.php");
      include ("../rainfall_ITI/jpgraph2.3/src/jpgraph_bar.php ");
      include 'dbconnect.php' ;

      $sql = mysql_query("SE LECT Rainfall,Date FROM rainfall WHERE Station_ID = 'st1 St 02' LIMIT 0, 10") or die(
      mysql_error());


      while($row = mysql_fetch_arr ay($sql))
      {
      $i=0;

      $Query1 = explode(" ",$row['Date']);
      $Query2 = $Query1[0];

      $data[] = $row[0];
      $leg[] = $Query2[8].$Query2[9];

      }

      $graph = new Graph(300,300," auto");// set the size of the image
      $graph->SetScale("text int");
      $graph->img->SetMargin(40,3 0,30,60);
      //$graph->AdjBackgroundI mage(0.4,0.7,-1); //setting BG type
      //$graph->SetBackgroundI mage("linux_pez .png",BGIMG_FIL LFRAME); //adding image
      $graph->SetShadow();

      $graph->xaxis->SetTickLabels( $leg);
      $bplot = new BarPlot($data);
      $bplot->SetFillColor(" darkblue"); // Fill color

      // Set up the title for the graph
      //$graph->title->Set("Rainfal l During last 10 hours"."($Query 2)");
      $graph->title->Set("Rainfal l During last 10 hours");
      $graph->title->SetFont(FF_VER DANA,FS_NORMAL, 10);
      $graph->title->SetColor("dark red");

      // Setup X-axis labels
      $graph->xaxis->title->Set("Date");
      //$graph->xaxis->SetLabelAngle( 90);
      $graph->yaxis->title->Set("Rainfall( mm)");

      $bplot->value->Show();
      $bplot->value->SetFont(FF_ARI AL,FS_BOLD);
      $bplot->value->SetAngle(45) ;
      $bplot->value->SetColor("blac k","navy");

      $graph->Add($bplot);
      $graph->Stroke(); ?>

      [/PHP]


      when i put the above code in to my table it gave an error
      [PHP]
      <table>
      <tr>
      <td width="60">&nbs p;</td>
      <td>
      /* jp graph code add here*/
      </td>
      </tr>
      </table>
      [/PHP]

      Comment

      • TheServant
        Recognized Expert Top Contributor
        • Feb 2008
        • 1168

        #4
        Are there any headers set in
        "../rainfall_ITI/jpgraph2.3/src/jpgraph.php" and "../rainfall_ITI/jpgraph2.3/src/jpgraph_bar.php "

        Comment

        • ghjk
          Contributor
          • Jan 2008
          • 250

          #5
          Originally posted by TheServant
          Are there any headers set in
          "../rainfall_ITI/jpgraph2.3/src/jpgraph.php" and "../rainfall_ITI/jpgraph2.3/src/jpgraph_bar.php "
          This is the first few lines in jpgraph.php
          [PHP]
          <?php
          //=============== =============== =============== =============== ===========
          // File: JPGRAPH.PHP
          // Description: PHP Graph Plotting library. Base module.
          // Created: 2001-01-08
          // Ver: $Id: jpgraph.php 957 2007-12-01 14:00:29Z ljp $
          //
          // Copyright 2006 (c) Aditus Consulting. All rights reserved.
          //=============== =============== =============== =============== ============

          require_once('j pg-config.inc.php' );
          require_once('j pgraph_gradient .php');
          require_once('j pgraph_errhandl er.inc.php');
          require_once('j pgraph_ttf.inc. php');

          // Version info
          DEFINE('JPG_VER SION','2.3');

          // Minimum required PHP version
          DEFINE('MIN_PHP VERSION','5.1.0 ');

          // Should the image be a truecolor image?
          DEFINE('USE_TRU ECOLOR',true);
          ............... ............... ....

          [/PHP]

          Comment

          • TheServant
            Recognized Expert Top Contributor
            • Feb 2008
            • 1168

            #6
            If it's a header problem, it's likely to be in one of those files. Provided you ahven't changed any orders of those include commands from the original set up, my bet would be 'jpg-config.inc.php' . What I am looking for and what you can look for is the php function header() like header(Location :somepage.php). If you can find that, there's where your prob is. I hope I'm not leading you on a wild goose chase, but if you're getting a header warning it's a good thing to look for. Another thing is do you have session_start() anywhere?

            Comment

            • ghjk
              Contributor
              • Jan 2008
              • 250

              #7
              Originally posted by TheServant
              If it's a header problem, it's likely to be in one of those files. Provided you ahven't changed any orders of those include commands from the original set up, my bet would be 'jpg-config.inc.php' . What I am looking for and what you can look for is the php function header() like header(Location :somepage.php). If you can find that, there's where your prob is. I hope I'm not leading you on a wild goose chase, but if you're getting a header warning it's a good thing to look for. Another thing is do you have session_start() anywhere?

              Thanks for your reply. But i could not understand about header thing? I don't have session_start() in any jpgraph pages. but having all my ather pages.

              Comment

              • Ranjan kumar Barik
                New Member
                • Aug 2007
                • 95

                #8
                Originally posted by ghjk
                when i put the above code in to my table it gave an error
                [PHP]
                <table>
                <tr>
                <td width="60">&nbs p;</td>
                <td>
                /* jp graph code add here*/
                </td>
                </tr>
                </table>
                [/PHP]
                I don't think you can use jp Graph code like this inside a table or even inside a html file.
                It must be a separate pure php file. Otherwise if server found any html code before your php code, it will start sending them to browser before processing your jp Graph code and so you will get an error like header already send.
                To solve this, I think you can can create a separate jp Graph file with the code you have, run the code, save the graph image and display it inside your table. To get the updated image, you have to run the jp Graph file and save the image automatically.

                Thanks

                Comment

                • ghjk
                  Contributor
                  • Jan 2008
                  • 250

                  #9
                  Originally posted by Ranjan kumar Barik
                  I don't think you can use jp Graph code like this inside a table or even inside a html file.
                  It must be a separate pure php file. Otherwise if server found any html code before your php code, it will start sending them to browser before processing your jp Graph code and so you will get an error like header already send.
                  To solve this, I think you can can create a separate jp Graph file with the code you have, run the code, save the graph image and display it inside your table. To get the updated image, you have to run the jp Graph file and save the image automatically.

                  Thanks
                  Could you please tell me how can i do that? Really in a trouble..

                  Comment

                  • Ranjan kumar Barik
                    New Member
                    • Aug 2007
                    • 95

                    #10
                    Originally posted by ghjk
                    Could you please tell me how can i do that? Really in a trouble..
                    You just create a php file for you graph. Then at the end in the graph->stroke() function give a path to where you want to save the graph image.

                    [PHP]graph->stroke('file path');[/PHP]

                    See if it is saved or not. The path must have a file permission to save the image. If its done then you put the hole code inside a function. Pass all parameters the function requires and call it in your pages. Every time your page loads the function will be called and the image will be replaced with the updated one. Then you can show the saved image anywhere you want.

                    You function should be defined before you call it.

                    :)

                    Comment

                    Working...