Home > Article > Backend Development > How to solve php jpgraph garbled problem
# Recommended: "php jpgraph garbled solution: 1. Modify the font of the title to solve the title garbled problem; 2. Modify the "jpgraph_legend.inc.php" file and set the relevant attributes to public.
PHP Video Tutorial 》
Recently, due to project needs, a JpGraph plug-in in php was used to solve drawing problems. During this period, I encountered many problems, specifically:1. How to use the composer package manager to install and load.
2. How to solve the problem of garbled Chinese characters in drawings (title and Legend)
Execute
composer update to install
JpGraph::load();
JpGraph::module('line'); <br><br>
You need to execute the load() function first. The load() function will include the main function. When drawing the line chart, you need to introduce another file. jpgraph_line.php, at this time you need to use the
JpGraph::module('line') method to introduce the function, and no error will be reported. The php7 version will have a warning prompt for the construction method, and the configuration error prompt level will be ignored.
class JpGraph { static $loaded = false ; static $modules = array(); static function load(){ if(self::$loaded !== true){ include_once __DIR__.'/jpgraph/src/jpgraph.php'; self::$loaded = true ; } } static function module($moduleName){ self::load(); if(!in_array($moduleName,self::$modules)){ $path = __DIR__.'/jpgraph/src/jpgraph_'.$moduleName.'.php' ; if(file_exists($path)){ include_once $path ; }else{ throw new ModuleNotFoundException('The JpGraphs\'s module "'.$moduleName.'" does not exist'); } } } }Garbled code problemThe title and lenged logo will be garbled when displayed. I checked many blog solutions, and most of them solve the title garbled problem by modifying the font of the title.
$graph->title->SetFont(FF_SIMSUN,FS_BOLD);
Can solve the garbled problem of the title:
legend solution is to modify the underlying code of composer.
Modified the jpgraph_legend.inc.php file.
class Legend There is such a sentence in the class
private $font_family=FF_FONT1,$font_style=FS_NORMAL,$font_size=12;
The latest version of the existing code has set this attribute to public,
You can change the font through the
$graph->legend->font_family = FF_SIMSUN;
statementSet font command Just execute it before the image is output;
$graph->title->SetFont(FF_SIMSUN,FS_BOLD); $graph->legend->font_family = FF_SIMSUN; $image_file = $path; return $graph->Stroke($image_file);
Pay special attention here to place the font file under the /usr/share/fonts/truetype
path. You need to put these two files:
simhei.ttf
, simsun.ttc
The above is the detailed content of How to solve php jpgraph garbled problem. For more information, please follow other related articles on the PHP Chinese website!