2017-02-22 10 views
0

저는 웹용 파이 차트와 응용 프로그램 (영어 + 아랍어) 다국어 사이트 (pdf보기)를 작성 중입니다. 웹 버전 용 나는 영어와 아랍어 모두보기 PDF에 대한 잘 작동하는 원형 차트를 만들기위한 JQplot js 플러그인을 사용하고 있습니다. 나는 Jpgraph PHP 라이브러리를 사용하고 있습니다. 아랍어로보기의 PDF 버전은 입니다. 문제는 전설이 역순으로오고 있습니다. 여기 범례가 아랍어 jpgraph에서 역순으로 변환됩니다.

pdf view

web view

내가 PDF에 대한 파이 차트를 생성하기 위해 사용하고있는 코드입니다.
function create_graph($chart_array, $plan_id,$lang,$site_lang){ 

require_once dirname(dirname(dirname(__FILE__))).'/application/third_party/jpgraph/src/jpgraph.php'; 
require_once dirname(dirname(dirname(__FILE__))).'/application/third_party/jpgraph/src/jpgraph_pie.php'; 

if(!empty($chart_array)){ 
    foreach($chart_array as $chart){ 
     if ($site_lang=='ar') { 
      $leg[] = $this->utf8_strrev($chart['0']); // to fix the reverse order issue originally it was only ($leg[] = $chart['0'] - no condition) 
     }else{ 
      $leg[] = $chart['0']; 
     } 

     $data[] = $chart['1']; 
    } 

    $flag = true; 
    foreach($data as $_data){ 
     if($_data != 0) 
      $flag = false; 
    } 
    if(!$flag){ 
    // Create the Pie Graph. 
      $graph = new PieGraph(1000,950,"auto"); 
      $graph->SetShadow(); 
      $graph ->legend->Pos(0.25,0.8,"right" ,"right"); 
      //$graph->legend->SetFont(FF_VERDANA,FS_BOLD,12); 
      $graph->title->SetMargin (20); 

      // Create plots 
      $size=0.25; 
      $p1 = new PiePlot($data); 
      $p1->SetLegends($leg); 
      $p1->SetSize($size); 
      $p1->SetGuideLines(true,false); 
      $p1->SetGuideLinesAdjust(1.8,3); 
      $p1->SetCenter(0.25,0.32); 
      //$p1->value->SetFont(FF_VERDANA); 
      $p1->title->Set($lang->line('initial_investment_data')); 

      $p1->title->SetMargin(45); 
      $p1->SetSliceColors(array('red','orange','yellow','green','purple','blue','brown','black')); 
      $graph->Add($p1); 
      $graph->Stroke('assets/graph/initial_investment_'.$plan_id.'.png'); 
    } 
} 
} 

는이에

function utf8_strrev($str){ 
    preg_match_all('/./us', $str, $ar); 
    return join('', array_reverse($ar[0])); 
} 

다음 내가 사용했던 역순으로 문제를 해결하기 위해 내가 무엇입니까 모든 공간 (예는 : 버그 흘려 넣기로 변경)로 반전 문자열입니다, 그래서이 단어를 푼다 의미.

jpgraph가 범례를 뒤집는 이유와이 역 문제를 해결하는 방법을 찾을 수 없습니다.

답변

1

이 문제는 해결되었습니다. 동료가 도와주었습니다.

이것은 Jpgraph가 아니라 php gd 라이브러리에서 문제가되는데, 그래프 이미지를 만들 때 글꼴로 인해 범례 텍스트를 되 돌리는 php Gd 라이브러리입니다.

require_once '/application/third_party/ar-php/I18N/Arabic.php'; 

$Arabic = new I18N_Arabic('Glyphs'); 

$this->Arabic->utf8Glyphs($legend_name); 

이 잘 작동합니다 : 우리가 확장 AR-PHP

You need to do the following: 

1) download library and put that in your project 
2) Include the library file 
3) Create a object of the class 
4) user the object to convert the legend in Arabic with correct font . 

코드 아래

https://sourceforge.net/projects/ar-php/

을 사용하고이 문제를 해결합니다.