在 laravel 中设置 phpChart
环境:亚马逊 EC2.Ubuntu x64.(已安装 GD 库)我最近在 laravel 框架中使用 phpChart 进行图形和报告.我被困在了开始阶段.
Environment:Amazon EC2. Ubuntu x64. (GD library installed) I'm recently using phpChart for graph and report in laravel framework. I'm stuck at the beginning stage.
这就是我所做的.
- 1.将phpChart_Lite中的内容解压到/var/www/app/libraries/phpChart.
2.编辑composer.json并添加:
- 1.Unzip the contents in phpChart_Lite to /var/www/app/libraries/phpChart.
2.Edit composer.json and add :
"autoload": {
"classmap": [
...
"app/libraries"
]
},
3.run:composer dump-autoload
3.run:composer dump-autoload
4.修改phpChart_Lite中的conf.php
4.modify conf.php in phpChart_Lite
define('SCRIPTPATH',app_path().'/libraries/phpChart_Lite/');
这是我的测试页代码:
<?php
require_once(app_path()."/libraries/phpChart_Lite/conf.php");
$pc = new C_PhpChartX(array(array(11, 9, 5, 12, 14)),'basic_chart');
$pc->draw();
?>
ps.my app_path() 被echo app_path()"验证为/var/www/app".
ps.my app_path() is verified by "echo app_path()" and it is "/var/www/app".
这是我的错误信息:
Unknown: Failed opening required '/var/www/public//var/www/app/libraries/phpChart_Lite//conf.php'
(include_path='/var/www/vendor/phpseclib/phpseclib/phpseclib:.:/usr/share/php:/usr/share/pear')
推荐答案
经过大量的尝试和错误,我想我还是找到了根本原因.实际上有两个主要问题.这是我的解决方案.
After a lot of try-and-error, I somehow found the root cause, I guess. There are actually two main issue there. And here's my solution.
1.对于我在第一篇文章中解释的问题.在 phpChart_Lite 文件夹中的 conf.php 文件中.SCRIPTPATH 以某种方式以/var/www/public 为前缀.
1.For my issue explained in the very first post. In the conf.php file in phpChart_Lite folder. The SCRIPTPATH is somehow prefixed with /var/www/public.
但是,在我的 apache2.conf 文件中,将目录声明为/var/www.不管这个前缀如何,我都使用 SCRIPTPATH 的绝对路径.以下修改对我有用:
However, in my apache2.conf file states the directory to be /var/www. Regardless this prefix, I use a absolute path for SCRIPTPATH. The following modification works for me:
define('SCRIPTPATH','../app/libraries/phpChart_Lite/');
错误消失了.但是出现了第二个问题,即图表没有出现.打开 Chrome 开发者工具(按 F12).在控制台"选项卡上,我发现加载 phpChar_Lite/js 时出现错误 404.错误信息之一如下:
The error was gone. But the second issue appears, that is the chart doesn't show up. Open the Chrome Developer Tool(press F12). On the 'Console' tab, I found error 404 for loading phpChar_Lite/js. One of the error messages as following:
http://myip/app/libraries/phpChart_Lite/js/highlighter/styles/zenburn.css
作为 Laravel 的设计,只有 public 文件夹可以通过外部请求访问.所以我得到了第二个问题.这是我的解决方案.(不是安全方法)
As the design of Laravel, only public folder can be access by external request. So I got second issue. And here's my solution.(not a secured method)
2.将 phpChart_Lite 移至公用文件夹.修改测试页代码:
2.Move the phpChart_Lite to public folder. Modify the code of test page:
include_once(public_path()."/phpChart_Lite/conf.php");
修改public/phpChart_Lite中的conf.php:
Modify the conf.php in public/phpChart_Lite:
define('SCRIPTPATH','phpChart_Lite/');
现在一切都很好.
如果您认为 phpChart 配置过于复杂,您可能想尝试 pChart2.0.它不需要太多设置.但是图表非常丑陋.
If you consider phpChart is too complicate to configure with, you might want to try pChart2.0. It doesn't require much setting. But the graph is terribly ugly.
我更喜欢 phpChart 因为它的图形和函数调用,虽然设置有点复杂而且对 laravel 不友好.
I prefer phpChart for it's graph and function calls, though the setting is a little complicated and not laravel friendly.
相关文章