Home > Backend Development > PHP Tutorial > jpgraph中报错" 图像因其本身有错无法显示"

jpgraph中报错" 图像因其本身有错无法显示"

WBOY
Release: 2016-06-23 13:58:40
Original
778 people have browsed it

因为中文乱码的问题,我加了一行设置中文字体的语句$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);
但是加上后就报错图像因其本身有错无法显示
如果去掉这句,或者将中文改成英文就没有问题
查了网上说要加一句ob_clean();清除之前的输出,但是不知道加在哪里?求前辈指点。

下面是代码

<?php require_once ('jpgraph/jpgraph.php');require_once ('jpgraph/jpgraph_bar.php');$datay1=array(13,8,19,7,17,6);$datay2=array(4,5,2,7,5,25);// Create the graph.$graph = new Graph(350,250);$graph->SetScale('textlin');$graph->SetMarginColor('silver');// Setup title$graph->title->Set('支持布什的人数统计(万)');$graph->title->SetFont(FF_SIMSUN,FS_BOLD,14);// Create the first bar$bplot = new BarPlot($datay1);$bplot->SetFillGradient('AntiqueWhite2','AntiqueWhite4:0.8',GRAD_VERT);$bplot->SetColor('darkred');// Create the second bar$bplot2 = new BarPlot($datay2);$bplot2->SetFillGradient('olivedrab1','olivedrab4',GRAD_VERT);$bplot2->SetColor('darkgreen');// And join them in an accumulated bar$accbplot = new AccBarPlot(array($bplot,$bplot2));$graph->Add($accbplot);ob_clean();$graph->Stroke();?>
Copy after login


回复讨论(解决方案)

将中文改成英文就没有问题
显然你的中文字库设置有误

将中文改成英文就没有问题
显然你的中文字库设置有误



请问代码应该怎么修改呢,请指点,谢谢。

视频教程里的代码也是这么写的,怎么就没问题呢。FF_SIMSUN字体是支持中文的。

1.字体是否存在,名字是否相同->FF_SIMSUN 是个常量,所以要检视其具体值和你的系统是否相符
2.编码

我也遇到你说的问题了,请问你找到方法了吗?求指导啊

$title="支持布什的统计情况(万)";
$title = iconv("UTF-8", "gb2312", $title);

$graph->title->Set($title);



已经解决了!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template