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!

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

报告相同问题?

悬赏问题

  • ¥50 求恶意流量检测系统搭建教程( C++ python C)
  • ¥15 mmseqs内存报错
  • ¥15 vika文档如何与obsidian同步
  • ¥15 华为手机相册里面的照片能够替换成自己想要的照片吗?
  • ¥15 陆空双模式无人机飞控设置
  • ¥15 sentaurus lithography
  • ¥100 求抖音ck号 或者提ck教程
  • ¥15 关于#linux#的问题:子进程1等待子进程A、B退出后退出(语言-c语言)
  • ¥20 web页面如何打开Outlook 365的全球离线通讯簿功能
  • ¥15 io.jsonwebtoken.security.Keys