dshp9580656 2014-02-16 17:47
浏览 36
已采纳

如何在CakePHP中使用GoogleCharts插件?

I have been messing around with different visualization plugins which allows you to represent data in the form of charts.. and following my previous post, It seems that it is a bit outdated, and out of desperation I looked for other plugins which may offer similar options.

Now, I have realised that googleCharts might have just what I need, and as it turns out, there is a cake googlechart plugin which should be able to do what I need. However, I am having a little bit of trouble understanding how I will implement it.

From what I have seen here and in the plugin doc, it accepts data in the form of an array of results, from which is then iterated, and displaying the fields which match, specified in the columns key. (If I'm not correct, please do explain.)

Otherwise, I am looking for a way I can generate a pie chart using values returned from 3 queries as follows:

        $users_donor = $this->User->find('count' , array(
            'conditions' => array('User.role' => 'donor') 
        ));

        $users_staff = $this->User->find('count' , array(
            'conditions' => array('User.role' => 'staff') 
        ));
        $users_admin = $this->User->find('count' , array(
            'conditions' => array('User.role' => 'admin') 
        ));

Basically I want to show a visual representation of all the current registered users, grouped by their role.. Is there a way I can pass in the latter 3 count values (i.e users_donor,users_staff,users_admin)

  • 写回答

1条回答 默认 最新

  • douhan0562 2014-02-16 20:08
    关注

    I had to think backwards for this one. The problem was that I was still trying to make use of the code I was using for the other plugin mentioned in my previous post (ie, I was retrieving the count values in separate variables.)

    As you might have guessed, all I needed to do is retrieve that same information in an array using cakePHP query method to perform an SQL query and groupBy role!

    Here it is:

    $results = $this->User->query(
            "SELECT users.role as user_role, 
                Count(users.role) AS user_count
                FROM users
                GROUP BY users.role"
             );
    

    Allowing me to use the results array in conjunction with googleCharts plugin!

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

报告相同问题?

悬赏问题

  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求