SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict I don`t mind's Avatar
    Join Date
    Feb 2006
    Location
    LA
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jpgraph - picture background

    hi there, I am using jpgraph to generate a graph now I am wondering why I am getting an error when I try to set an picture as graph background

    PHP Code:
    <?php
    /** 
     *  Generate jpgraph
     * 
     */ 

    define ("API_EXECUTE_ACTION_DEFINED"1) ;

    function 
    api_execute_action2 ()
    {

        include (
    FW_LIB_PATH "\jpgraph\jpgraph.php");
        include (
    FW_LIB_PATH "\jpgraph\jpgraph_bar.php");
        
    include_lists();

        
    //Get the data
        
    $sql 'SELECT name,counter FROM bibliography_t_books';
        
    $lists = new lists('Counter''-counter');
        
    $db_lists $lists->get_list($sql);
        
    $datay = array(); //array for the data of the parts of the grap
        
    $datax = array(); //array for the data of the legend
        
    $dataz = array(); //array for the titles of the x-axis
        
    if (is_array($db_lists)) {
            
            
    //only the top ten books are used
            
    while ((list($rows) = each($db_lists)) && $rows 10) {
                
                
    //counter has to be bigger than 0 ... 0 won't be showed in the graph
                
    if ($db_lists[$rows][1] > 0) {
                    
                    
    //set the data for the parts of the graph
                    
    $datay[$rows] = $db_lists[$rows][1];
                    
                    
    //count the length of the books' name
                    
    $count strlen($db_lists[$rows][0]);
                    
                    
    //name of the book shouldn't be longer than 15 letters otherwise it will be shortened
                    
    if ($count 15) {
                        for (
    $i=0;$i<15;$i++) {
                            
    $dataz[$rows] .= $db_lists[$rows][0][$i];
                        }
                        
    $dataz[$rows] .= ' ...';
                    } else {
                        
    $dataz[$rows] = $db_lists[$rows][0];    
                    }
                    
    $dataz[$rows] .= ' (' $db_lists[$rows][1] . ')';
                }
            }
        }
        
        
        
    // Setup the graph. 
        
    $graph = new Graph(700,490,"auto");
        
    $graph->title->Set("Books' Top Ten");
        
    $graph->img->SetMargin(60,20,60,180);
        
    $graph->SetScale("textlin");
        
    $graph->SetMarginColor("#DADADA");
        
    $graph->SetShadow();

        
    // Set up the title for the graph
        
    $graph->title->Set("Top Ten Books");
        
    $graph->title->SetMargin(20,10,10,10);
        
    $graph->title->SetFont(FF_VERDANA,FS_BOLD,15);
        
    $graph->title->SetColor("#7E1264");

        
    // Setup font for axis
        
    $graph->xaxis->SetColor("#7E1264");
        
    $graph->xaxis->title->Set("Book");
        
    $graph->xaxis->title->SetFont(FF_VERDANA,FS_NORMAL,13);
        
    $graph->xaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
        
        
    $graph->yaxis->SetFont(FF_VERDANA,FS_NORMAL,10);
        
    $graph->yaxis->title->Set("Counter");
        
    $graph->yaxis->title->SetFont(FF_VERDANA,FS_NORMAL,13);
        
    $graph->yaxis->title->SetMargin(15,10,10,10);

        

        
    // Hide 0 label on Y-axis (default is not to show)
        
    $graph->yscale->ticks->SupressZeroLabel(true);

        
    // Setup X-axis labels
        
    $graph->xaxis->SetTickLabels($dataz);
        
    $graph->xaxis->SetLabelAngle(50);

        
    // Create the bar pot
        
    $bplot = new BarPlot($datay);
        
    $bplot->SetWidth(0.3);

        
    // Setup color for gradient fill style 
        
    $bplot->SetFillGradient("#800080","#7E1264",GRAD_LEFT_REFLECTION);

        
    // Set color for the frame of each bar
        
    $bplot->SetColor("purple");
        
    $graph->Add($bplot);
        
        
    //Set the background to computershare logo
        
    $graph->SetBackgroundImage('cs_logo.jpg',BGIMG_COPY);

        
    // Finally send the graph to the browser
        
    $graph->Stroke();

        
        RETURN 
    true;
    }

    ?>
    Words are weapons of Mass Destruction.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, what is the error? its probably descriptive at least a bit. use that info to help you.

    in any case, make sure the image exists at the location you specified. in your case, the same dir as your php script.

  3. #3
    SitePoint Addict I don`t mind's Avatar
    Join Date
    Feb 2006
    Location
    LA
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It says can't read background image: 'cslogo.gif'

    I already checked if the script file and the image are in the same folder...
    Words are weapons of Mass Destruction.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    echo getcwd();

    that is php's current working dir. all filepaths must be relative to this dir.

  5. #5
    SitePoint Addict I don`t mind's Avatar
    Join Date
    Feb 2006
    Location
    LA
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so I moved my picture to the folder of getcwd() but it still don't work ... have no idea why

    PHP Code:
    //Set the background to computershare logo
        
    $graph->SetBackgroundImage(getcwd() . '\cslogo.jpg',BGIMG_COPY); 
    Words are weapons of Mass Destruction.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •