recherche
Maisonphp教程php手册解决JpGraph中文乱码问题的方法

JpGraph是一个非常不错的图形类库了,我们可以直接使用它生成各种柱状图,饼图,折线图并且还可以增加文字说明了,在增加英文数字时没有问题,但增加中文汉字说明时会发现乱码问题,对此小编整理了一些解决JpGraph中文乱码问题的方法供各位参考。

JpGraph为什么会出现中文乱码

在JpGraph中默认是要把字符串转成utf8的,但是如果你的文件本身就是utf8的,并且要用中文字体,它还会转一遍,结果多转了一次,就会出现乱码。如图所示

JpGraph使用详解之中文乱码解决方法

解决JpGraph中文乱码问题的方法,取前篇的代码片断如下:

//设置图表的标题字体、大小 
$graph->title->Set("Accumulated bar plots"); 
$graph->xaxis->title->Set("X-title"); 
$graph->yaxis->title->Set("Y-title"); 
//和上面标题对应,设置标题的字体和大小 
$graph->title->SetFont(FF_FONT1,FS_BOLD); 
$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); 
$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); 
//把它改为 
//设置图表的标题字体、大小 
$graph->title->Set(iconv("UTF-8","GB2312//IGNORE","网志博客信息统计表"));  
$graph->xaxis->title->Set(iconv("UTF-8","GB2312//IGNORE","X-标题")); 
$graph->yaxis->title->Set(iconv("UTF-8","GB2312//IGNORE","Y-标题")); 
//和上面标题对应,设置标题的字体和大小 
$graph->title->SetFont(FF_SIMSUN,FS_BOLD); 
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD); 
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);

使用php函数据中文由UTF-8转为GB2312,记住由于iconv本身的一个bug,iconv在转换字符"-"到gb2312时会出错,所以在需要转成的编码后加上 "//IGNORE".

FF_SIMSUN表示中文简体,对应的字体文件是simsun.ttc,虽然FF_CHINESE和FF_BIG5也表示中文但是它们对应的字体文件是不同的,所以不要弄错.

解决JpGraph中文乱码问题的方法,下面是本例调试的完整代码:

require_once ('jpgraph/jpgraph.php'); 
require_once ('jpgraph/jpgraph_bar.php'); 
$data1y=array(0,8,9,3,5,6); 
$data2y=array(18,2,1,7,5,4); 
// Create the graph. These two calls are always required 
$graph = new Graph(500,400); 
$graph->SetScale("textlin"); 
$graph->SetShadow(); 
$graph->img->SetMargin(40,30,20,40);//设置图形的边距 
// Create the bar plots 
$b1plot = new BarPlot($data1y); 
$b1plot->SetFillColor("orange"); 
$b1plot->value->Show(); 
$b2plot = new BarPlot($data2y); 
$b2plot->SetFillColor("blue"); 
$b2plot->value->Show(); 
// Create the grouped bar plot 
$gbplot = new AccBarPlot(array($b1plot,$b2plot)); 
// ...and add it to the graPH 
$graph->Add($gbplot); 
//设置标题字体样式 
$graph->title->Set(iconv("UTF-8","GB2312//IGNORE","网志博客信息统计表")); 
$graph->xaxis->title->Set(iconv("UTF-8","GB2312//IGNORE","X-标题")); 
$graph->yaxis->title->Set(iconv("UTF-8","GB2312//IGNORE","Y-标题")); 
$graph->title->SetFont(FF_SIMSUN,FS_BOLD); 
$graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD); 
$graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD); 
$graph->Stroke();

当然了,我这里只介绍了一种方法,还有一种就是修改源码,但不推荐,因为我觉得改动源码可能会给其它地方带来意想不到的麻烦.

使用JpGraph,要知道其版本、运行服务器以及操作系统的息息,不能张冠李戴,否则麻烦多多,好了,至此JpGraph使用介绍也就这么多了.


永久地址:

转载随意~请带上教程地址吧^^

Déclaration
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Meilleurs paramètres graphiques
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Comment réparer l'audio si vous n'entendez personne
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Commandes de chat et comment les utiliser
1 Il y a quelques moisBy尊渡假赌尊渡假赌尊渡假赌

Outils chauds

Version crackée d'EditPlus en chinois

Version crackée d'EditPlus en chinois

Petite taille, coloration syntaxique, ne prend pas en charge la fonction d'invite de code

mPDF

mPDF

mPDF est une bibliothèque PHP qui peut générer des fichiers PDF à partir de HTML encodé en UTF-8. L'auteur original, Ian Back, a écrit mPDF pour générer des fichiers PDF « à la volée » depuis son site Web et gérer différentes langues. Il est plus lent et produit des fichiers plus volumineux lors de l'utilisation de polices Unicode que les scripts originaux comme HTML2FPDF, mais prend en charge les styles CSS, etc. et présente de nombreuses améliorations. Prend en charge presque toutes les langues, y compris RTL (arabe et hébreu) ​​et CJK (chinois, japonais et coréen). Prend en charge les éléments imbriqués au niveau du bloc (tels que P, DIV),

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver Mac

Dreamweaver Mac

Outils de développement Web visuel