Suppose if you wish to create an interactive dashboard creating reports in Google charts and deliver these charts (reports) responsively through Liferay, allowing these reports to interact with each other. In other words, if you select a bar or part of chart or product category in one chart, you want the other reports on the page to refresh based on the event and the selection made of chart.
Mainly google charts are used to represent data with charts, we can identify our data or progress bar or whatever we are looking for it.
1. Create A Liferay Plug-in portet Your Dashboard.
You can use following reference link to create liferay portlet
Note: Configure controller class to get data from DB by Java code or Liferay API’s
Your jsp (page) must have as many HTML elements (typically < div > s) to hold both the dashboard, the controls and charts. While instantiating dashboard, control, and chart instances, pass a reference to their element, so assign an ID to each HTML element.
2. Load Your Libraries
A dashboard requires only two libraries to be included or loaded on the page: the Google AJAX API and the Google Visualization controls package. The API (in particular, google.visualization.ChartWrapper) automatically identifies the other packages needed and loads them on the fly without further intervention.
You must use google.charts.load() to fetch the control library.
We can download/save this js libraries and add it in portlet docroot/js folder and confugure it in liferay-portlet.xml file
We can add this js libraries in liferay theme as well.
3. Prepare Your Data
When the Visualization API has been loaded, google.charts.setOnLoadCallback() will call your handler function, so you know that all the required helper methods and classes will be ready for you to start preparing your data.
Dashboards accepts data in a DataTable, the same as charts.
Note: We can prepare this data dynamically as well(By fetch from DB).
4. Create a Dashboard Instance
After you have created your data, you can instantiate your dashboard object. A dashboard constructor takes one parameter: a reference to the DOM element in which to draw the dashboard.
5. Create Control and Chart Instances
Define as many instances you need for each control and chart, that will be part of the dashboard. Use google.visualization.ChartWrapper and google.visualization.ControlWrapper to define charts and controls respectively.
A few tips about configuring controls and charts:
You must give all controls a filterColumnIndex (or filterColumnLabel) to specify which column of your google.visualization.DataTable the control operates on (in the example above, the control operates on the column labeled Donuts eaten),
Use the state configuration option on controls to initialize them with an explicit state when they are first drawn. For example, use this setting to fix the initial positions of the thumbs of a range slider control.
All the charts that are part of a dashboard share the same underlying dataTable you prepared in the Prepare Your Data step. However, charts often require a specific arrangement of columns to display correctly: for example, a pie chart requires a string column for the label, followed by a number column for the value.
Use the view option while configuring each ChartWrapper instance to declare which columns are relevant for the chart, as in the following example.
6. Draw Your Dashboard
Call the draw() method on the dashboard instance to render the entire dashboard. The draw() method takes only one parameter: the DataTable (or DataView) that powers the dashboard.
You should call draw() every time you change the composition of the dashboard (for example by adding new controls or charts to it) or you change the overall DataTable that powers it.
The dashboard instance fires a ready event whenever draw() terminates drawing all the controls and charts that are part of it. An error event is fired if any of the managed controls or chart fails to draw. To learn more about handling events, see Handling Events.
Note: You should listen for the ready event before you try to change the dashboard composition or draw it again.
7. Programmatic Changes after Draw
Once the dashboard completes the initial draw() it will be live and respond automatically to any action you perform on it (such as changing the selected range of a control slider that is part of the dashboard).
If you need to alter the dashboard state, you can do so by operating directly on the ControlWrapper and ChartWrapper instances that are part of it. The rule of thumb is to perform any change you need directly on the specific ControlWrapper (or ChartWrapper) instance: for example, change a control option or state via setOption() and setState() respectively, and call its draw() method afterward. The dashboard will then update to match the requested changes.