In our earlier blog “EFW for Creating a Report“, we have discussed about how to create a report using EFW and necessary files required to implement it. For creating a Tabular report using EFW method, there are 4 files required to visualize it which are
- EFW (.efw) – Entry point of the report. It contains the information required to run the report.
- HTML (.html) – Layout of the report.
- EFWVF (.efwvf) – Visualization of the data using javascript.
- EFWD (.efwd) – Data sources are defined here.
Following are the steps to generate a tabular report using an EFW method
Sample Tabular Report to be shown as output
Step1 : Create an EFW
file and define required information to run a report. Save the file with extension .efw
.
This file contains the information required to run the report.
<?xml version="1.0" encoding="UTF-8" ?> <efw> <title>Prepare Report</title> <author>name of creator</author> <description>Stage wise detailed information you can get it from this dashboard</description> <icon>images/image.ico</icon> <template>display.html</template> <visible>true</visible> <style>clean</style> </efw>
Tag Details
- <title> : This tag holds the name of the report as will be visible in the file browser of the application.
- <author> : This tag is used to hold the name of the creator.
- <description> : This tag holds a brief description of the report.
- <icon> : Path to the icon to be displayed along with the name of the report.
- <template> : Name of the HTML file which will be invoked by the EFW.
- <visible> : Boolean value to show or hide the dashboard in the file explorer.
Step2 : Create an HTML file where report layout is defined. The HTML page is used to display the visualizations on the screen. This file is where the
- layout of the report is defined
- the required JS and CSS files are called
- CSS is defined
- scripts are written
- charting components are defined
Now, Save the file with extension .html
.
NOTE: <html>
, <head>
and <body>
tags should not be added in the HTML file.
Charting component:
The charting components are defined as follow –
var genderPieChart = { name: "genderPieChart", type: "chart", vf : { id : 1, file : "MedicalRecords.efwvf" // enter EFWVF file name }, htmlElementId : "#genderPieChart", executeAtStart: true };
'name' :
Define the name of the component. The component will be accessed by this name.'type' :
By default set to ‘chart’.'vf' :
Defines the VF file and the VF id in that file is to be used to visualize the data. (i)'id' :
Defines the VF id to be used from the said VF file. (ii)'file' :
Defines the VF file to be used for visualization.
'htmlElementId' :
Holds the HTML element ID where the chart will be bound for display.'executeAtStart' :
Boolean value to decide if the component will execute at start or will be triggered on some event.
The charting components are initialized as follows :
var dashboard = Dashboard; var components = [genderPieChart]; dashboard.init(components);
The Dashboard Variables are set retrieved as follows :
Set - dashboard.setVariable('gender', 'male'); Get - var gender = dashboard.getVariable('gender');
These variables can be used for passing data between different files as parameters or as triggers to be listened to for any change in value.
Example :
<link rel="stylesheet" type="text/css" href="getExternalResource.html?path=resources/jquery.dataTables.css" /> <link rel="stylesheet" type="text/css" href="getExternalResource.html?path=resources/dataTables.jqueryui.css" /> <link rel="stylesheet" type="text/css" href="getExternalResource.html?path=resources/c3.css" /> <link rel="stylesheet" href="getExternalResource.html?path=resources/pivottbl/pivot.css" type="text/css" /> <script src="getExternalResource.html?path=resources/c3.js"></script> <script src="getExternalResource.html?path=resources/jquery.dataTables.js"></script> <script src="getExternalResource.html?path=resources/pivottbl/pivot.js"></script> <script src="getExternalResource.html?path=resources/jquery_pivot.js"></script> <script src="getExternalResource.html?path=resources/jquery-ui-1.9.2.custom.min.js"></script> <style type="text/css"> .heading { text-align: center; } </style> <div class="row"> <div class=”heading col-sm-12”> <h2>Pie Chart<h2></div> <div id="genderPieChart col-sm-12"></div> </div> <script> var dashboard = Dashboard; dashboard.resetAll(); dashboard.setVariable('gender', ''); var genderPieChart = { name: "genderPieChart", type: "chart", vf : { id : 1, file : "MedicalRecords.efwvf" }, htmlElementId : "#genderPieChart", executeAtStart: true }; var components = [genderPieChart]; dashboard.init(components); </script>
<script>
// <![CDATA[
var dashboard = Dashboard; dashboard.resetAll(); dashboard.setVariable('gender', ''); var genderPieChart = { name: "genderPieChart", type: "chart", vf : { id : 1, file : "MedicalRecords.efwvf" }, htmlElementId : "#genderPieChart", executeAtStart: true }; var components = [genderPieChart]; dashboard.init(components);// ]]>
</script>
Step3 : Create an EFWVF file for visualizing a data using Javascript Code. The EFWVF
(henceforth referred to as ‘VF’) file is the visualization file used for visualizing the data in the form that is desired. The 'Charting component'
in the HTML file points to a VF file and a VF id. Whenever that component is triggered, the specified VF file is accessed by the application and the specified VF id is used to create the visualization.
Now, save the file with extension .efwvf
.
Template
<Charts>
<Chart id ="1">
<prop>
<name>Tabular Chart</name>
<type>Custom</type>
<DataSource>5</DataSource>
<script>
<![CDATA[
// Insert Javascript code for applying predefined customization in case
of Tabular report
]]>
</script>
</prop>
</Chart>
<Chart id ="2">
<prop>
<name>Pie Chart</name>
<type>Custom</type>
<DataSource>6</DataSource>
<script>
<![CDATA[
// Insert Javascript code for applying customization
]]>
</script>
</prop>
</Chart>
//Similarly more chart customization can be added in a EFWVF file
</Charts>
<Chart id ="1">
: This id is used by the ‘Charting Component’ of the HTML file to access the desired VF component.<name>
: This helps identify what that VF component does. This is for the developers convenience.<type>
: Default value is ‘custom’.<DataSource>
: This tag defines the id of the query in the EFWD file which will be fired to fetch the resultset to be visualized.<script>
: This tag contains<![CDATA[ ]]>
tag, which holds the actual javascript to create the chart.
NOTE: The result set from the query is passed as a JSON array variable named ‘data’.
Sample Code for reference
<Charts>
<Chart id ="1">
<prop>
<name>Tabular Chart</name>
<type>Custom</type>
<DataSource>5</DataSource>
<script>
<![CDATA[
$(document).ready(function() {
var table = $('#example').DataTable({
'ajax': 'https://api.myjson.com/bins/qgcu',
'responsive': {
'details': {
'type': 'column',
'target': 0
}
},
'columnDefs': [{
'data': null,
'defaultContent': '',
'className': 'control',
'orderable': false,
'targets': 0
}],
'columns': [
{ 'data': null },
{ 'data': 0 },
{ 'data': 1 },
{ 'data': 2 },
{ 'data': 3 },
{ 'data': 4 },
{ 'data': 5 }
],
'select': {
'style': 'multi',
'selector': 'td:not(.control)'
},
'order': [[1, 'asc']]
});
});
]]>
</script>
</prop>
</Chart>
</Charts>
Note: In a single EFWVF file, multiple chart id’s can be created. Here, chart id=1 is defined for Tabular report. Similarly, other chart id’s can be created for other charts/table such as pie chart, donut chart and so on.
Step4 : Then, Create an EFWD
file for defining Datasource details. EFWD file is the DataSource file, which contains all the queries required to create a report. Each query is assigned a unique id, which the VF file uses, to fire a specific query and access its result set. Save the file with extension .efwd
.
Template
<EFWD> <DataSources> <Connection id="1" type="sql.jdbc"> <Driver>com.mysql.jdbc.Driver</Driver> <Url>jdbc:mysql://127.0.0.1:3306/efw_db_POC_DM</Url> <User>root</User> <Pass>root</Pass> </Connection> </DataSources> <DataMaps> <DataMap id="1" connection="1" type="sql" > <Name>Sql Query on SampleData - Jdbc</Name> <Query> <![CDATA[ SELECT * FROM table WHERE stage_id IN ${stage_id} AND order_date > ${orderDate} ]]> </Query> <Parameters> <Parameter name="stage_id" type="Collection" default="'1','2'"/> <Parameter name="orderDate" type="Date" pattern="yyyy-MM-dd" default="2003-03-01"/> </Parameters> </DataMap> </DataMaps> </EFWD>
- <DataSources> : This tag defines the data sources being used for the report.
- <Connection id=”1″ type=”sql.jdbc”> : The connection id is a unique id given to each connection and the type specifies the type of connection it is.
- <Driver> : Specifies the driver of the database being used.
- <Url> : URL of the database being used.
- <User> : Username credential for the database.
- <Pass> : Password credential for the database.
- DataMap id=”1″ connection=”1″ type=”sql” > :‘id’ : This Id is used by VF to specify which query to fire.
‘connection’ : This specifies which datasource connection is to be used. - <Name> : This is the label, specifying what the query does.
- <Query> : Contains the tag containing the query.
- <![CDATA[ ]]> : Contains the actual query.
- <Parameters> : Contains the parameters to be passed to the query.
- <Parameter name=”stage_id” type=”Collection” default=”‘1’,’2′”/> :
‘name’ : The name of the variable.
‘type’ : The type of the variable (collection/string/date/etc.).
‘default’ : The default value of the variable if nothing passed.
Sample
<EFWD> <DataSources> <Connection id="1" type="sql.jdbc"> <Driver>org.postgresql.Driver</Driver> <Url>jdbc:postgresql://192.168.2.9:5432/Global_DataBase</Url> <User>postgres</User> <Pass>postgres</Pass> </Connection> </DataSources> <DataMaps> <DataMap id="1" connection="1" type="sql" > <Name>Gender wise classification</Name> <Query> <![CDATA[ select count(case when gender = 'Male' then 1 end) as "Male", count(case when gender = 'Female' then 1 end) as "Female", count(case when gender is null then 1 end) as "NotSpecified" from medical_records ]]> </Query> </DataMap> </DataMaps> </EFWD>
After creating all the required files, save these file in a single folder. Also, save the folder in Helical Insight repository which can be accessed through Helical Insight Application.
For further assistance, kindly contact us on support@helicalinsight.com or post your queries at forum.helicalinsight.com