duanmo6937 2015-06-11 22:13
浏览 93
已采纳

用于PhantomJS + Highcharts的Javascript中的PHP

I have just configured phantomjs which is working fine. I have it installed in order to create charts from highcharts and include them in automated email through cronjobs, based on user's info.

This will be done in php and right now I have the execution running perfectly. My php is:

exec('/usr/bin/phantomjs myscript.js');

and my test myscript.js is:

var page = require('webpage').create();
page.open('http://github.com/', function() {
page.render('github.png');
phantom.exit();
});

This saves github.png in the same directory so all is good. But I need to do this with highcharts and all the examples I found have static data (with apples, bananas, and all that as filler data). If I need to have this created dynamincally from data stored in a sql table can I use php within the javascript to get the user info?

For example I'd like to do something like below:

    ...title: {
        text: 'Combination chart'
    },
    xAxis: {
        categories: [<? echo $xaxis; ?>]
    },...

How can I accomplish this? Am I able to pass paramaters through the exec function in my original php file? Thanks!

  • 写回答

1条回答 默认 最新

  • dongwei8440 2015-06-12 02:05
    关注

    So I've figured it out. To anyone having the same issue here's the answer:

    in php file calling myscript.js use the following format for passing arguments through exec():

    exec('/usr/bin/phantomjs myscript.js param1 param2',$op,$er);
    

    Then in the js file do the below to get the parameters passed:

    var args = require('system').args;
    var page = require('webpage').create();
    var address = args[1];
    var saveme = args[2];
    page.open(address, function() {
       page.render(saveme);
       phantom.exit();
    });
    

    Voila!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题