Skip to main content
4 / 4
タグを編集
cubick
  • 2.1万
  • 5
  • 27
  • 64

pChartで作ったグラフで日本語が表示できない

pChartで日本語を含むグラフを作成したいですが、タイトルが文字化けしてしまい読めないです。

LAMP環境

  • VirtualBox 5.0.6
  • CentOS 6.5
  • PHP 5.3
  • Apache 2.2
  • MySQL 5.1
  • pChart 2.14

php.iniで下記を設定をしました。

;mbstring.internal_encoding = EUC-JP → mbstring.internal_encoding = UTF-8
;mbstring.language = Japanese → mbstring.language = Japanese
;mbstring.http_input = auto → mbstring.http_input = auto
;mbstring.detect_order = auto → mbstring.detect_order = auto

test.php

<?php 

include("class/pData.class.php");
include("class/pDraw.class.php");
include("class/pImage.class.php");

$myData = new pData();
$myData->addPoints(array(12,11,32,4,90,48),"Serie1");
$myData->setSerieDescription("Serie1","Aさん");
$myData->setSerieOnAxis("Serie1",0);

$myData->addPoints(array(22,60,3,0,15,22),"Serie2");
$myData->setSerieDescription("Serie2","Bさん");
$myData->setSerieOnAxis("Serie2",0);

$myData->addPoints(array("1月","2月","3月","4月","5月","6月"),"Absissa");
$myData->setAbscissa("Absissa");

$myData->setAxisPosition(0,AXIS_POSITION_LEFT);
$myData->setAxisName(0,"1st axis");
$myData->setAxisUnit(0,"");

$myPicture = new pImage(500,230,$myData);
$Settings = array("R"=>170, "G"=>183, "B"=>87, "Dash"=>1, "DashR"=>190, "DashG"=>203, "DashB"=>107);
$myPicture->drawFilledRectangle(0,0,500,230,$Settings);

$Settings = array("StartR"=>219, "StartG"=>231, "StartB"=>139, "EndR"=>1, "EndG"=>138, "EndB"=>68, "Alpha"=>50);
$myPicture->drawGradientArea(0,0,500,230,DIRECTION_VERTICAL,$Settings);

$myPicture->drawRectangle(0,0,499,229,array("R"=>0,"G"=>0,"B"=>0));

$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>50,"G"=>50,"B"=>50,"Alpha"=>20));

$myPicture->setFontProperties(array("FontName"=>"fonts/sazanami-gothic.ttf","FontSize"=>14));
$TextSettings = array("Align"=>TEXT_ALIGN_MIDDLEMIDDLE , "R"=>255, "G"=>255, "B"=>255);
$myPicture->drawText(250,25,"販売実績",$TextSettings);

$myPicture->setShadow(FALSE);
$myPicture->setGraphArea(50,50,475,190);
$myPicture->setFontProperties(array("R"=>0,"G"=>0,"B"=>0,"FontName"=>"fonts/sazanami-gothic.ttf","FontSize"=>8));

$Settings = array("Pos"=>SCALE_POS_LEFTRIGHT , "Mode"=>SCALE_MODE_ADDALL_START0 , "LabelingMethod"=>LABELING_DIFFERENT , "GridR"=>255, "GridG"=>255, "GridB"=>255, "GridAlpha"=>20, "TickR"=>0, "TickG"=>0, "TickB"=>0, "TickAlpha"=>50, "LabelRotation"=>0, "CycleBackground"=>1, "DrawXLines"=>1, "DrawSubTicks"=>1, "SubTickR"=>255, "SubTickG"=>0, "SubTickB"=>0, "SubTickAlpha"=>50, "DrawYLines"=>ALL);
$myPicture->drawScale($Settings);

$myPicture->setShadow(TRUE,array("X"=>1,"Y"=>1,"R"=>50,"G"=>50,"B"=>50,"Alpha"=>10));

$Config = array("DisplayValues"=>1, "Gradient"=>1, "AroundZero"=>1);
$myPicture->drawBarChart($Config);

$Config = array("FontR"=>0, "FontG"=>0, "FontB"=>0, "FontName"=>"fonts/sazanami-gothic.ttf", "FontSize"=>8, "Margin"=>6, "Alpha"=>30, "BoxSize"=>5, "Style"=>LEGEND_ROUND , "Mode"=>LEGEND_VERTICAL );
$myPicture->drawLegend(50,15,$Config);

$myPicture->stroke(); 
?> 

TeraPad で test.php を編集しています。文字コードを SHIFT-JIS にして保存・実行すると、グラフが表示できますが、日本語は文字化けします。
文字コードを UTF(UTF-8N) にして保存・実行すると、グラフが表示できません。

どのようにすれば、日本語のグラフが表示できますか?

ご教示よろしくお願いいたします。

nice
  • 109
  • 3
  • 5
  • 12