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.
- Install to group analytics. Plugin will not work in any other groups.
- 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.
- 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]
- <params> showld contain these parameters as default:
- Chart height (as text field)
- Date range (as hidden field with values 1/0)
- Group by (as hidden field with values 1/0)
- < 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 7- 11.
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