こんにちは、レポートに Jpgraph を使用しており、Codeigniter Ajax-Jquery-Json を使用しています。これが私の状況です:
ブラウザに画像が表示されず、Firebug コンソールで次の応答が返されます: 画像と illisible Characters をエンコードします
コード:
コントローラ:
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;
});
});