Tuesday, September 7, 2010

Jpgraph and Zend Framework: The image “ ” cannot be displayed, because it contains errors

Problem: My Below Code failed to produce Jpgraph Graph and give the above Error.

set_time_limit(0);
        require ("jpgraph/jpgraph.php");
        require ("jpgraph/jpgraph_pie.php");
        require ("jpgraph/jpgraph_pie3d.php");

        // set the directory where images are cached by JpGraph
        //$jpgcache = APACHE_CACHE_DIR;

        $tran =  new Model_Report();
        $result = $tran->all_transaction_req();

        foreach($result as $row)
        {
        $level[]=$row['tran_req_date'];
        $data[]=$row['amount'];
        }
        //print_r($data);
        //exit;
        $graph_name = 'chart.png';
        $graph = new PieGraph(500,400,"auto");
        $graph->SetShadow();

        // Set A title for the plot
        $graph->title->Set("Transaction Statistics");
        $graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
        $graph->title->SetColor("darkblue");
        $graph->legend->Pos(0.0,0.1,"right","top");


        // Create pie plot
        $p1 = new PiePlot3d($data);
        $p1->SetTheme("sand");
        $p1->SetCenter(0.4);
        $p1->SetAngle(45);
        $p1->value->SetFont(FF_ARIAL,FS_NORMAL,12);
        $p1->SetLegends($level);
        #$p1->SetLabels($level);
        $p1->SetLabelMargin(5);
        $p1->SetLabelPos(0.9);


        $graph->Add($p1);

        header ("Content-type: image/png" );
        $graph->Stroke();
        


Sloution: add exit; after  $graph->Stroke();
       .......
       ........
       $graph->Stroke();
       exit;


Source: Internet

3 comments:

  1. Oh man! Thank you so much. You've saved my day!

    Regards.

    ReplyDelete
  2. comment je corrige cette erreur

    ReplyDelete
  3. hola soy alex de colombia y para mostrarla en la vista solo tienes que coloca esto

    view
    grap.phtml
    img src="url(array('controller' =>
    'index','action'=> 'grafico',)); ?>



    Y enjoy!!!!! sorry my inglish

    asalas79@gmail.com cuestion only spanish

    ReplyDelete