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!

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

报告相同问题?

悬赏问题

  • ¥15 Simulink仿真报错,请问如何解决
  • ¥20 宝塔面板无法添加Node项目,一直处于正在添加脚本页面
  • ¥50 Dkeil5 CT107D单片机的程序编写
  • ¥30 Ubuntu20.04中PVN3D复现过程交叉编译问题
  • ¥15 模拟电路求复阻抗和传递函数,请各位拍照写一下解答过程
  • ¥60 不懂得怎么运行下载来的代码
  • ¥15 CST导出3D模型图为什么和软件显示不一样?
  • ¥15 加热反应炉PLC控制系统设计(相关搜索:梯形图)
  • ¥15 python 用Dorc包报错,我的写法和网上教的是一样的但是它显示无效参数,是什么问题
  • ¥15 经过滑动平均后的一维信号还原用什么结构好呢?