0

嗨,我使用 Jpgraph 进行报告,我使用 Codeigniter Ajax-Jquery-Json。这是我的情况:

图像未出现在浏览器中,我在 Firebug 控制台中收到此响应:编码图像和不可见字符

代码:

控制器:

function RapportByRegion()

{
    $this->load->model('rapport');
    $item = trim($this->input->post('variable'));
    //$array = array('result' => $item);
    header('Content-Type: application/json',true);

       $data = array();
        $casregion = $this->rapport->RapportByRegion($item);
        $casregionlegende = $this->rapport->RapportByRegionLegende($item);

        $graph = $this->jpgraph->Reporting($casregion,'Nombre de cas par structure',$casregionlegende);
        $graphTempDirectory = 'temp';

        $graphEnterName = 'casregion.png';
        $graphFileLocationE = $graphTempDirectory . '/' . $graphEnterName;
        $graph->Stroke('./' . $graphFileLocationE);
        $data['graph4'] = $graphFileLocationE;
        echo json_encode($data);

}

Jpgraph类:

class Jpgraph {

    function Reporting($ydata, $title, $legends) {
        require_once "jpgraph/jpgraph.php";
        require_once "jpgraph/jpgraph_pie.php";
        require_once "jpgraph/jpgraph_pie3d.php";

        $graph = new PieGraph(500, 500);
        $graph->SetShadow(true,5,'red');
        $graph->legend->SetShadow('darkgray@0.5');
        $graph->title->Set($title);
        $graph->title->SetFont(FF_FONT1, FS_BOLD);
        $graph->legend->Pos(0.12,0.89,"right","top");
        $graph->img->SetMargin(60,80,30,40);

        $plot = new PiePlot3D($ydata);
        $plot->SetLabelType(PIE_VALUE_ABS);
        $plot->value->SetFormat('%d Cas');
        $plot->ExplodeSlice(4);
        $plot->SetLegends($legends);
        $graph->legend->SetPos(0, 0.15);
        //$graph->legend->SetSize(0.10);
        $plot->SetSize(0.25);
        $plot->SetCenter(0.5);
        $graph->Add($plot);
        return $graph;
    }

}

jQuery代码:

$(document).ready(function() {
$( '#region').change(function(){
    var regionid = $('#region').val();

        if (regionid != ""){
            var variable_de_test = regionid;
        var post_url = "/index.php/report/RapportByRegion/" + regionid;
            $.ajax({
               type: "POST",
               dataType: "json",
               url: post_url,
               data :{variable : variable_de_test}, 
               async:false,
               success: function(result) //we're calling the response json array 'cities'
                {
                    //alert(region.result);
                 $('#rapports').hide();
                 $('#cas-region').html('<img src="<?php echo site_url();?>/"'+result.graph4+' />');                

                } //end success


             }); //end AJAX
        } 
     return false;   
    });

}); 
4

0 回答 0