{"id":173,"date":"2008-02-03T02:24:18","date_gmt":"2008-02-02T18:24:18","guid":{"rendered":"http:\/\/learn-house.idv.tw\/?p=173"},"modified":"2010-01-17T18:52:41","modified_gmt":"2010-01-17T10:52:41","slug":"phplinux%e4%b8%8b%e4%bd%bf%e7%94%a8jpgraph%e9%a1%af%e7%a4%ba%e4%b8%ad%e6%96%87%e5%ad%97%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/learn-house.idv.tw\/?p=173","title":{"rendered":"[PHP]linux\u4e0b\u4f7f\u7528jpgraph\u986f\u793a\u4e2d\u6587\u5b57\u578b"},"content":{"rendered":"<p>\u9019\u500b\u554f\u984c\u8b93\u6211\u82b1\u4e86\u5feb\u4e00\u500b\u79ae\u62dc\u7684\u6642\u9593\uff0c\u672c\u4f86\u4e00\u5ea6\u60f3\u653e\u68c4\u4f7f\u7528jpgraph\u6539\u7528\u5716\u7247\u7684\u653e\u5f0f\u4f86\u986f\u793a\u5716\u8868<\/p>\n<p>\u4f46\u4eca\u5929\u65e9\u4e0a\u4e00\u9192\u4f86\uff0c\u89ba\u5f97\u60f3\u60f3\uff0c\u6211\u82b1\u4e86\u90a3\u9ebc\u591a\u6642\u9593\u8490\u96c6\u8cc7\u6599\u8207\u6e2c\u8a66<\/p>\n<p>\u7adf\u7136\u5728\u9019\u4e00\u523b\u8981\u6211\u5f9e\u627e\u53e6\u4e00\u500b\u65b9\u6cd5\uff0c\u771f\u7684\u5f88\u4e0d\u7518\u5fc3<\/p>\n<p>\u56e0\u6b64\u6211\u53c8\u5f9e\u65b0\u8a66\u4e86\u4e00\u6b21\uff0c\u628a\u53ef\u80fd\u6703\u5c0e\u81f4\u7121\u6cd5\u986f\u793a\u4e2d\u6587\u6216\u662f\u4e2d\u6587\u4e82\u78bc\u7684\u53ef\u80fd\u539f\u56e0\uff0c\u91cd\u65b0\u7684\u6392\u5217\u7d44\u5408<\/p>\n<p>\u4e00\u500b\u4e00\u500b\u53bb\u4fee\u6539\u6838\u5fc3\u7a0b\u5f0f\u78bc\uff0c\u6700\u5f8c\u7d42\u65bc\u8b93\u6211\u6b78\u985e\u51fa\u5e7e\u500b\u9700\u8981\u6539\u7684\u9805\u76ee<\/p>\n<p>\u7531\u65bc\u6539\u5f88\u591a\uff0c\u6709\u4e9b\u5df2\u7d93\u5fd8\u8a18\u662f\u6211\u6539\u7684\u9084\u662f\u539f\u672c\u7684\u4e86\uff0c\u6240\u4ee5\u4ee5\u4e0b\u65b9\u6cd5\u662f\u6211\u89ba\u5f97\u53ef\u80fd\u5f71\u97ff\u7684\u5e7e\u500b\u8981\u6539\u7684\u9805\u76ee&nbsp;<\/p>\n<p><strong>1.\u4fee\u6539src\/jpgraph.php<\/strong><\/p>\n<p>require_once(&#39;jpg-config.inc.php&#39;);<br \/>require_once(&#39;jpgraph_gradient.php&#39;);<br \/>require_once(&#39;jpgraph_errhandler.inc.php&#39;);<br \/>require_once(&#39;jpgraph_ttf.inc.php&#39;);<\/p>\n<p>\/\/ Version info<br \/>DEFINE(&#39;JPG_VERSION&#39;,&#39;2.3&#39;);<\/p>\n<p>\/\/ Minimum required PHP version<br \/>DEFINE(&#39;MIN_PHPVERSION&#39;,&#39;5.1.0&#39;);<\/p>\n<p>\/\/ Should the image be a truecolor image? <br \/>DEFINE(&#39;USE_TRUECOLOR&#39;,true);<\/p>\n<p>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>\/\/ Automatic settings of path for cache and font directory<br \/>\/\/ if they have not been previously specified<br \/>\/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>if(USE_CACHE) {<br \/>&nbsp;&nbsp;&nbsp; if (!defined(&#39;CACHE_DIR&#39;)) {<br \/>&nbsp;&nbsp;&nbsp; if ( strstr( PHP_OS, &#39;WIN&#39;) ) {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if( empty($_SERVER[&#39;TEMP&#39;]) ) {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $t = new ErrMsgText();<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $msg = $t-&gt;Get(11,$file,$lineno);<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; die($msg);<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; else {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DEFINE(&#39;CACHE_DIR&#39;, $_SERVER[&#39;TEMP&#39;] . &#39;\/&#39;);<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; } else {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DEFINE(&#39;CACHE_DIR&#39;,&#39;\/tmp\/jpgraph_cache\/&#39;);<br \/>&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; }<br \/>}<br \/>elseif( !defined(&#39;CACHE_DIR&#39;) ) {<br \/>&nbsp;&nbsp;&nbsp; DEFINE(&#39;CACHE_DIR&#39;, &#39;&#39;);<br \/>}<\/p>\n<p>if (!defined(&#39;TTF_DIR&#39;)) {<br \/>&nbsp;&nbsp;&nbsp; if (strstr( PHP_OS, &#39;WIN&#39;) ) {<br \/>&nbsp;&nbsp;&nbsp; $sroot = getenv(&#39;SystemRoot&#39;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( empty($sroot) ) {<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $t = new ErrMsgText();<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $msg = $t-&gt;Get(12,$file,$lineno);<br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; die($msg);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; else {<br \/>&nbsp;&nbsp;&nbsp; &nbsp; DEFINE(&#39;TTF_DIR&#39;, $sroot.&#39;\/fonts\/&#39;);<br \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br \/>&nbsp;&nbsp;&nbsp; } else {<br \/>\/\/&nbsp;&nbsp;&nbsp; DEFINE(&#39;TTF_DIR&#39;,&#39;\/usr\/X11R6\/lib\/X11\/fonts\/truetype\/&#39;);\/\/<font color=\"#ff0000\">\u4fee\u6539\u6210\u4e0b\u9762\u7684\u8def\u5f91<\/font><br \/>&nbsp;&nbsp;&nbsp; DEFINE(&#39;TTF_DIR&#39;,&#39;\/usr\/share\/fonts\/zh_TW\/TrueType\/&#39;);<br \/>&nbsp;&nbsp;&nbsp; }<br \/>}<\/p>\n<p><font color=\"#008000\"><strong>Tips:<\/strong> \u8981\u6ce8\u610f\/usr\/share\/fonts\/zh_TW\/TrueType\/\u4e0b\u662f\u5426\u6709.ttf\u6216.ttc\u7684\u5b57\u578b\uff0c\u82e5\u6c92\u6709\u53ef\u5f9eWindows\u7cfb\u7d71\u7684fonts\u53bb\u8907\u88fd<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><strong>2.\u4fee\u6539src\/jpg-config.inc.php<\/strong><\/p>\n<p>DEFINE(&#39;CHINESE_TTF_FONT&#39;,&#39;bkai00mp.ttf&#39;);<\/p>\n<p>\u4fee\u6539\u6210DEFINE(&#39;CHINESE_TTF_FONT&#39;,&#39;<font color=\"#ff0000\">mingliu.ttc<\/font>&#39;);<\/p>\n<p><font color=\"#008000\"><strong>Tips:<\/strong> \u7d05\u8272\u7684\u90e8\u4efd\u53ef\u4f9d\u81ea\u5df1\u7684\u559c\u597d\u7684\u5b57\u578b\u4fee\u6539\uff0c\u800c\u5b57\u578b\u7684\u6a94\u6848\u8981\u5728\u4e0a\u8ff0\u7684\u8def\u5f91\u88e1\u9762\uff0c\u9019\u88e1\u4ee5\u65b0\u7d30\u660e\u9ad4mingliu.ttc\u70ba\u4f8b<\/font><\/p>\n<p>&nbsp;<\/p>\n<p><strong>3.\u4fee\u6539src\/jpgraph_ttf.inc.php<\/strong><\/p>\n<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; FF_CHINESE &nbsp;&nbsp;&nbsp; =&gt;&nbsp;&nbsp; array(FS_NORMAL&nbsp;&nbsp;&nbsp; =&gt;CHINESE_TTF_FONT, <br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; FS_BOLD&nbsp;&nbsp;&nbsp; =&gt;&#39;&#39;, <br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; FS_ITALIC&nbsp;&nbsp;&nbsp; =&gt;&#39;&#39;, <br \/>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; FS_BOLDITALIC&nbsp;&nbsp;&nbsp; =&gt;&#39;&#39; ),<br \/>\u4fee\u6539\u6210<\/p>\n<p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; FF_CHINESE &nbsp;&nbsp; &nbsp;=&gt;&nbsp;&nbsp; array(FS_NORMAL&nbsp;&nbsp; &nbsp;=&gt;&#39;mingliu.ttc&#39;, <br \/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; FS_BOLD&nbsp;&nbsp; &nbsp;=&gt;&#39;<font color=\"#ff0000\">mingliu.ttc<\/font>&#39;, <br \/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; FS_ITALIC&nbsp;&nbsp; &nbsp;=&gt;&#39;<font color=\"#ff0000\">mingliu.ttc<\/font>&#39;, <br \/>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; FS_BOLDITALIC&nbsp;&nbsp; &nbsp;=&gt;&#39;<font color=\"#ff0000\">mingliu.ttc<\/font>&#39; ),<\/p>\n<p>&nbsp;<\/p>\n<p><strong>4.\u518d\u4f86\u5c31\u662f\u5448\u73fe\u7e6a\u5716\u8cc7\u8a0a\u7684\u6a94\u6848\u4e86\uff0c\u53ef\u5f9eExample\u7684\u8cc7\u6599\u593e\u9078\u64c7\u60f3\u8981\u7684\u7bc4\u4f8b\u4fee\u6539 <\/strong><\/p>\n<p>$graph-&gt;title-&gt;Set(&quot;\u9019\u88e1\u9019\u6a23\u8a2d\u5b9a\u5c31\u53ef\u4ee5\u76f4\u63a5\u986f\u793a\u4e2d\u6587&quot;);<br \/>$graph-&gt;title-&gt;SetFont(FF_BIG5, FS_NORMAL);<\/p>\n<p><font color=\"#008000\"><strong>Tips1:<\/strong>\u4e0d\u904e\u82e5\u662f\u5f9e\u8cc7\u6599\u5eab\u53d6\u5f97utf-8\u7684\u5b57\u4e32\uff0c\u8981\u5148\u8f49\u6210big5\u7684\u7de8\u78bc\u683c\u5f0f<\/font><\/p>\n<p>\u4e0b\u9762\u7bc4\u4f8b\u662f\u5f9e\u8cc7\u6599\u5eab\u53d6\u5f97utf-8\u5b57\u4e32\u5f8c\u4e1f\u5165\u9663\u5217\uff0c\u9663\u5217\u518d\u8f49\u6210big5\u7de8\u78bc\uff0c\u6211\u53bb\u6389\u4e00\u4e9b\u5728\u8cc7\u6599\u5eab\u4e0a\u505a\u64f7\u53d6\u8cc7\u6599\u5224\u65b7\u7684\u7c21\u7565\u7a0b\u5f0f\u7247\u65b7<\/p>\n<p>for($i = 0 ; $i &lt;= 10 ; $i++) <br \/>{<br \/>&nbsp;&nbsp;&nbsp; $name[$i] = iconv(&quot;utf-8&quot;,&quot;big5&quot;,$name[$i]);<br \/>}<\/p>\n<p><font color=\"#008000\"><strong>Tips2:<\/strong>\u8f49\u63db\u7684\u52d5\u4f5c\u4e0d\u80fd\u5beb\u5728\u5448\u73fe\u7e6a\u5716\u8cc7\u8a0a\u7684php\u6a94\u6848\u4e2d\uff0c\u4e0d\u7136\u6703\u5c0e\u81f4\u5716\u8868\u7121\u6cd5\u986f\u793a<\/font><\/p>\n<p>&nbsp;<\/p>\n<p>\u6700\u5f8c\u518d\u4f86\u8aaa\u4e00\u500b\u6211\u9047\u5230\u7684\u554f\u984c\uff0c\u5c31\u662f\u5982\u4f55\u628aSetLegends($name3)\u4e5f\u80fd\u986f\u793a\u4e2d\u6587<\/p>\n<p>\u5176\u4e2d$name\u662f\u5f9e\u8cc7\u6599\u5eab\u53d6\u5f97\u7684utf-8\u8f49big5\u7684\u4e2d\u6587\u9663\u5217<\/p>\n<p>\u800c\u8981\u80fd\u5728SetLegends\u986f\u793a\uff0c\u5c31\u8981\u52a0\u5165$graph-&gt;legend-&gt;SetFont(FF_BIG5, FS_NORMAL);<\/p>\n<p>\u9019\u9ebc\u4e00\u4f86\u5c31\u80fd\u986f\u793a\u4e2d\u6587\u4e86&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp; <\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9019\u500b\u554f\u984c\u8b93\u6211\u82b1\u4e86\u5feb\u4e00\u500b\u79ae\u62dc\u7684\u6642\u9593\uff0c\u672c\u4f86\u4e00\u5ea6\u60f3\u653e\u68c4\u4f7f\u7528jpgraph\u6539\u7528\u5716\u7247\u7684\u653e\u5f0f\u4f86\u986f\u793a\u5716\u8868 \u4f46\u4eca\u5929\u65e9\u4e0a\u4e00\u9192\u4f86\uff0c<span class=\"post-excerpt-end\">&hellip;<\/span><\/p>\n<p class=\"more-link\"><a href=\"https:\/\/learn-house.idv.tw\/?p=173\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-173","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=173"}],"version-history":[{"count":0,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=\/wp\/v2\/posts\/173\/revisions"}],"wp:attachment":[{"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn-house.idv.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}