感觉可能是后部分((round(10000*($datLst[$i]/$tot))/100))由些问题!!有时可以、有时不可以,这个问题比较怪,你试一下换个字体文件试一下。

解决方案 »

  1.   

    换了simkai.ttf字体,也是相同现象。偶尔可以显示,大部分时间不能显示。
      

  2.   

    楼上的,已经用$str = iconv("GB2312", "UTF-8", $labLst[$i]);做了转换啊function draw_img($datLst,$labLst,$clrLst,$a=250,$b=120,$v=20,$font=10)
    {
        $ox = 5+$a;
        $oy = 35+$b;
        $fw = imagefontwidth($font);
        $fh = imagefontheight($font);
        $n = count($datLst);//数据项个数
        $w = 10+$a*2;
    //    $h = 10+$b*2+$v+($fh+2)*$n;
        $h = 10+$b+$v+($fh+2)*$n;
    //    $h = 10+$v+($fh+2)*$n;
        $img = imagecreate($w, $h);//转RGB为索引色 
        for($i=0; $i<$n; $i++)
            $clrLst[$i] = draw_getindexcolor($img,$clrLst[$i]);
        $clrbk = imagecolorallocate($img, 0xff, 0xff, 0xff);
        $clrt = imagecolorallocate($img, 0x00, 0x00, 0x00);//填充背景色 
        imagefill($img, 0, 0, $clrbk);
    //求和 
        $tot = 0;
        for($i=0; $i<$n; $i++)
             $tot += $datLst[$i];    $sd = 0;
        $ed = 0;
        $ly = 10+$b*2+$v;    for($i=0; $i<$n; $i++)
            { 
               $sd = $ed;
               $ed += $datLst[$i]/$tot*360;
    //画圆饼 
               draw_sector3d($img, $ox-150, $oy-50, $a, $b, $v, $sd, $ed, $clrLst[$i]); //$sd,$ed,$clrLst[$i]);//可控制位置
    //画标签 
               imagefilledrectangle($img, 235, $ly-250, 240+$fw, $ly+$fh-250, $clrLst[$i]);//可控制x、y位置
               imagerectangle($img, 235, $ly-250, 240+$fw, $ly+$fh-250, $clrt);//可控制x、y位置
    //           imagestring($img, $font, 5+2*$fw, $ly, $labLst[$i].":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)", $clrt);
               $str = iconv("GB2312", "UTF-8", $labLst[$i]);
    //可控制x、y位置,控制显示字体
               ImageTTFText($img, $font, 0, 245+2*$fw, $ly+13-250, $clrt, "f:/website/htdocs/tmp/font/simhei.ttf", $str.":".$datLst[$i]."(".(round(10000*($datLst[$i]/$tot))/100)."%)");
               $ly += $fh+2;
            }//输出图形 
        header("Content-type: image/png");
    //输出生成的图片
    //    $imgFileName = "../temp/".time().".png";
    //    imagepng($img,$imgFileName);
        imagepng($img);
    //释放资源 
        imagedestroy($img);
    }