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!

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

报告相同问题?

悬赏问题

  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥15 小红薯封设备能解决的来
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答
  • ¥20 在本地部署CHATRWKV时遇到了AttributeError: 'str' object has no attribute 'requires_grad'
  • ¥15 vue+element项目中多tag时,切换Tab时iframe套第三方html页面需要实现不刷新
  • ¥50 深度强化学习解决能源调度问题