2012-05-23 3 views
0

나는 PHP와 pchart로 그래프를 그리지 만, X 축에서 겹치지 않도록 어떤 긴 레이블을 보았는가?PHP - pchart 긴 레이블

또는 다른 솔루션?

+0

x 축을 그리는 코드 스 니펫을 제공 할 수 있습니까? – jugnu

+0

아직은 없지만이 http://pchart.sourceforge.net/screenshots.php?ID=10처럼 될 것입니다. –

답변

2

가끔 pchart2를 사용하고 설명 된 상황에서 개인적으로 pchart 코드 자체를 수정하는 경향이 있습니다.

레이블이 인쇄 된 곳을 검색하고 비틀기를 수행해야합니다. 안타깝게도, pchart의 코드는 ... 음 ... 글쎄, 제 의견으로는 좋지 않습니다. 그래서 쉽게 잃어 버릴 수 있습니다.

/** 
* Insert ends of line into the given string to prevent exceeding the given width of the 
* string when it is printed. 
* @param unknown_type $text String for separation by EOLs. 
* @param unknown_type $displayFont Font used for text printing. 
* @param unknown_type $displaySize Size of the printed text. 
* @param unknown_type $angle Angle of text printing. 
* @param unknown_type $maximumWidth Maximum allowed width (pixels). 
* @return string The edited input text. 
*/ 
function changeTextForMaximumWidth($text, $displayFont, $displaySize, $angle, $maximumWidth) { 

    $result = ""; 

    $processedText = $text; 
    $remainingText = ""; 

    while ($processedText != "") { 
     // replace this by any routine that computes the width and height of the text 
     $TxtPos = $this->getTextBox(0, 0, $displayFont, $displaySize, $angle, $processedText); 

     // what about TXT margin?? 
     $TxtWidth = abs($TxtPos[0]["X"] - $TxtPos[1]["X"]); 

     // if text length is sufficient 
     if ($TxtWidth <= $maximumWidth) { 

      $result .= $processedText; 
      if ($remainingText != "") { 
       $result .= PHP_EOL; 
      } 

      $processedText = $remainingText; 
      $remainingText = ""; 
      continue; 
     } 

     // the text is too wide 
     // try to make it shorter 
     $pos = strrpos($processedText, " "); 
     if ($pos == FALSE) { 
      // cannot be made shorter 
      $result .= $processedText; 
      if ($remainingText != "") { 
       $result .= PHP_EOL; 
      } 

      $processedText = $remainingText; 
      $remainingText = ""; 
      continue; 
     } 

     // can be shorten 

     $shorten = substr($processedText, 0, $pos); 

     $restLength = strlen($processedText) - ($pos + 1); 
     $rest = substr($processedText, $pos + 1, $restLength); 

     $processedText = $shorten; 
     $remainingText = $rest . " " . $remainingText; 
    } 

    return $result; 
} 
0

당신은에 word-wrap 기능을 사용하려고 할 수 있습니다

아마, 당신은 텍스트의 최대 허용 폭을 적용 할 하나 개 이상의 라인에 긴 텍스트를 분할하는 내 집에서 만든 기능을 주셔서 감사합니다 수 레이블의 텍스트가 짧아지고 여러 줄이 표시됩니다.