douduikai0562 2015-01-24 14:49
浏览 59
已采纳

带有PHP数组的Morris.js图表

I need your help for this case.

I have an array in PHP.

How can I apply this array:

$visits = $ga->query($params);

Witch gave me something like this:

Array
(
    [http_code] => 200
    [kind] => analytics#gaData
    [rows] => Array
        (
            [0] => Array
                (
                    [0] => 20141223
                    [1] => 26
                )

            [1] => Array
                (
                    [0] => 20141224
                    [1] => 15
                )
...

In this code :

<? function getVisits() { 
        $morris = new MorrisLineCharts('getVisits');
        $morris->xkey = array('date');
        $morris->ykeys = array('value');
        $morris->labels = array('Money');
        $morris->data = array(
            array('date' => '20141223', 'value' => 26),
            array('date' => '20141224', 'value' => 15),
        );
        echo $morris->toJavascript();
    }
    getVisits();
    ?>

Thanks a lot.

  • 写回答

1条回答 默认 最新

  • duankekan9269 2015-01-24 15:24
    关注

    You could loop over the data returned by Google Analytics, to construct an array suitable for Morris.

    <? function getVisits( $ga_rows = array() ) {
    
            foreach( $ga_rows as &$_row ) {
                 $_row = array('date' => $_row [0], 'value' => $_row [1]);
            }
    
            $morris = new MorrisLineCharts('getVisits');
            $morris->xkey = array('date');
            $morris->ykeys = array('value');
            $morris->labels = array('Money');
            $morris->data = $ga_rows;
            echo $morris->toJavascript();
        }
    
        // the relevant data from the array you retreived from Google Analytics
        getVisits( $google_analytics_data['rows'] );
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Linux权限管理相关操作(求解答)
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表
  • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符
  • ¥15 android 打包报错