Analytics - Create Report Plugin 【转】

 

To write plugin for Mighty Analytics is very simple. Reporter handle everything. You only need to create 4 events,onDrawChart, onChartData, onDrawTable, onGetTotals. I'll explain them one by one. But let me start with few points on installation XML file.

Powered by amCharts

The charts in this component use amCharts library. So to get documentation on how to create setting files and how to create data in XML format use their website. It is well documented. You do not need to use their files, everything needed already included in to Mighty Analytics component except Stock Type Charts as it is 1.0.0.0 Beta on the moment this component created. But this will be included in future versions or on first request from 3DP developer.

Installation XML

 

 

 

 

Installation file is usual as for any other plugins but you should note these points.

  1. Install to group analytics. Plugin will not work in any other groups.
  2. Line 14 - remember plugin name you set for plugin="" attribute. Later this name will be passed to every event to skip implementation if other plugin is called.
  3. Line 15 - you can place as many charts to report as you want as you will learn below, but every chart should have setting file. The setting file name constructed like [plugin-name]_settings[chart-key]
  4. <params> showld contain these parameters as default:
    1. Chart height (as text field)
    2. Date range (as hidden field with values 1/0)
    3. Group by (as hidden field with values 1/0)
  5. < params group="Advanced params"> - Advanced parameters are shown in the front-end to users and allow them to select parameters they need.
Plugin Construction

 

 

 

 

Class name and construct function have usual structure plg[group name][plugin name]

onDrawChart

 

 

 

 

This event define how many charts are in report and what is their type and size. You can see chart definition lines16 - 21. You can increase $chart++ and define another unlimited chart number. But I would suggest you to include only one chart per report unless it is very important to see few charts on one page to make some analysis.

$chart variable become the $key of the chart that is passed to every other event.

Line 3 - if($name != 'plugin_name') return; is the required line for every event.

Also if you create chart not for core Joomla component it is good to check if this component is installed like in line 711.

onChartData

This event create XML output for chart.

 

 

 

 

 

This event receive 4 arguments.

  • $data = this is parameter you should set final XML to. You do not need to return anything.
  • $key = Key of the chart defined by $chart in onDrawChart event.
  • $name = name of the plugin
  • $params = plugin parameters. Parameters contain all indexes you created in installation XML <prams> section and core parameters like start - date from, finish - date to, table - show table, xls - generate xls file.

In this function you do SQL query and build XML acording to amCharts format. I'll not exmplain it here. You can see example at the end of this article where I post all plugin source.

onDrawTable

 

 

 

This event is completely the same as previous instead of the first parameter. You also need to run SQL query here and build HTML table and set it to $table variable. You do not need to return anything. In this function there is a code that creates an XLS file that could be imported.

onGetTotals

 

 

 

This function receives 3 parameters. Here you run SQL query to get totals values (as many as you need) and set them into $totals variable. This event returns $totals array which includes value and text.

Whole plugin example

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值