Pricefx Classic UI is no longer supported. It has been replaced by Pricefx Unity UI.

 

Interactive Embedded Dashboards

With a few lines of Groovy code, it is very easy to embed a dashboard as a portlet of another dashboard. This creates an interactive dashboard which can change dynamically in reaction to an event. Clicking on a result in one portlet triggers an event, which changes the input (and therefore the content) of another, embedded portlet.

For example, you have a dashboard with a grid, which contains details about products, and a chart that graphically displays the product data. When you select a row in the grid (a particular product), you want to see the chart automatically updated so that it displays the correct data for the selected product.

In this section:

Advantages

The main reasons for using embedded dashboards are:

  • A single dashboard can be reused by embedding it within multiple main dashboards.

  • An embedded dashboard can be based on events and parameters provided by the main dashboard.

Code

Simply add a logic element that returns a DashboardApi instance:

return api.dashboard('<dashboard_name>').showEmbedded()

Of course, it is also possible to add more elements in the main dashboard.

Parameters

The main dashboard can provide input parameters to the embedded dashboard via DashboardApi.setParam(String param_name, Object param_value). The above example can be extended to:

return api .dashboard('<dashboard_name>') // Here the user can assign values to the embedded dashboard inputs .setParam('Customer Id', 'CD-00067') // ... and of course this means it could also "forward" its own inputs .setParam('Product Id', api.input('Product Id')) // Show the dashboard embedded ... .showEmbedded()

The embedded dashboard can then read the parameters via api.input(String param_name):

def sku = api.input('Product Id') def customer = api.input('Customer Id') // these can now be used, e.g. to build a chart api.newChartBuilder().newBarLine().addSeries() .setLabel('Invoice Price p/u') .setDatamart('DM.datamart_transaction') .setCurrency('EUR') .addDimFilter('ProductID', sku) // <=== .addDimFilter('CustomerID', customer) // <=== .setAxisX('Country') .setAxisY('InvoicePrice').withPerUnit().back() .setType(SeriesType.BAR) .withSortByAxisY(SortType.ASCENDING) .back() .build()

Events

Every event has its source (e.g. a grid) and a payload – arbitrary data (e.g. values of grid columns), which are passed to the dashboard portlet. Elements which can trigger an embedded dashboard to receive new parameters are:

ResultMatrix

The ResultMatrix element can trigger an embedded dashboard to receive new parameters and be rendered again. 

The event is triggered by a row click, and withColValueAsEventDataAttr() must be called for each column for which values should be added as a payload of the event. Only single selections of grid rows are supported.

Main Dashboard - Matrix Element

def matrix = someQueryResult.toResultMatrix()

matrix.onRowSelection().triggerEvent('<event_name>')
                       .withColValueAsEventDataAttr('<column_name>', '<param_name>')

// events are global through browser tabs, so they are not limited to embedded dashboards
// we provide a utility that constructs an event name that is unique to the current dashboard
def event_name = api.dashboardWideEvent('<event_name>')

matrix.onRowSelection().triggerEvent(event_name)
                       .withColValueAsEventDataAttr('<column_name1>', '<attribute_name1>')
                       .withColValueAsEventDataAttr('<column_name2>', '<attribute_name2>')

Main Dashboard - Embedded Element

def event_name = api.dashboardWideEvent('<event_name>')

return api  .dashboard('<dashboard_name>').showEmbedded()

            // replaced by the event payload
            //.setParam('<param_name1>', 'CD-00067')
            //.setParam('<param_name2>', 'MB-0012')

            .andRecalculateOn(event_name)

            // expose the event payload

            .withEventDataAttr('<attribute_name1>').asParam('<param_name1>')
            .withEventDataAttr('<attribute_name2>').asParam('<param_name2>')

The embedded dashboard's logic can read the parameters as api.input('<param_name1>') and api.input('<param_name2>').

Open Embedded Dashboard on New Tab 

An embedded dashboard can be opened as a separate dashboard on a new browser tab. Parameters are passed on in the URL.

Matrix Element

def matrix = someQueryResult.toResultMatrix()

def event_name = api.dashboardWideEvent('recalculateDashboard')

m.onRowSelection().triggerEvent(event_name)
                       .withColValueAsEventDataAttr('Column1', 'DA1')
                       .withColValueAsEventDataAttr('Column2', 'DA2')
					   .withColValueAsEventDataAttr('Column3', 'DA3')

return matrix;

Embedded Element

def event_name = api.dashboardWideEvent('recalculateDashboard')

return api  .dashboard("EmbeddedResultMatrixDashboard")
            // assign values to the embedded dashboard inputs
            .setParam('Typed ID', '***')
            // assign values to the embedded dashboard inputs
            .setParam('Typed ID2', '123')
            // "forward" its own inputs
            .setParam('Typed ID3', api.input('Typed ID3'))
	        .openInTabOrRecalculateOn(api.dashboardWideEvent('recalculateDashboard'))
            // Show the dashboard embedded ...
//            .showEmbedded()
//			.andRecalculateOn(event_name)
			.withEventDataAttr('DA1').asParam('Typed ID')
			.withEventDataAttr('DA3').asParam('Typed ID3')

ScatterChart

A chart generating click events that can send parameters and refresh an embedded dashboard is the ChartBuilder's ScatterChart.

It is possible to get both the AggregationBy (i.e. GroupBy) and BandBy dimensions of the clicked point.

Main Dashboard - Chart Element

def scatter = api.newChartBuilder().newScatter()

scatter.getOptions()
            .setTitle('Title')
            .setDisableDrilldown(true)
            // etc.

scatter.addSeries()
            .setLabel('Series1')
            // etc.

scatter.onClick()
            .triggerEvent(api.dashboardWideEvent('<event_name>'))
                  .withAggregationByAsEventDataAttr()   // attribute_name = 'aggregationBy'
                  .withBandByAsEventDataAttr()          // attribute_name = 'bandBy'

Main Dashboard - Embedded Element

def event_name = api.dashboardWideEvent('<event_name>')

return api  .dashboard('<dashboard_name>').showEmbedded()
            .andRecalculateOn(event_name)

            // expose the event payload
            .withEventDataAttr('aggregationBy').asParam(<param_name1>)
            .withEventDataAttr('bandBy').asParam(<param_name2>)

The embedded dashboard's logic can read the parameters as api.input('<param_name1>') and api.input('<param_name2>').

BarLineChart

Another chart that can generate click events is the ChartBuilder's BarLineChart.

The only data provided so far is the X axis category of the clicked bar.

Main Dashboard - Chart Element

def barChart = api.newChartBuilder().newBarLine()

barChart.getOptions()
            .setTitle('Title')
            .setDisableDrilldown(true)
            // etc.

barChart.addSeries()
            .setLabel('Series1')
            // etc.

barChart.onClick()
            .triggerEvent(api.dashboardWideEvent('<event_name>'))
                  .withXAsEventDataAttr()   // attribute_name 'x'

Main Dashboard - Embedded Element

def event_name = api.dashboardWideEvent('<event_name>')

return api  .dashboard('<dashboard_name>').showEmbedded()
            .andRecalculateOn(event_name)

            // expose the event payload
            .withEventDataAttr('x').asParam('<param_name>')

The embedded dashboard's logic can read the parameter as api.input('<param_name>').

Data Tab of any Chart (except Waterfalls)

Mainly with the DataTable chart (but also with the Data tab of any other chart type except Waterfall and WaterfallComparison), it is possible to subscribe to row level and cell level click events. The event can provide values of some or all of the dimensions shown in the grid, by calling one of these methods:

  • withAnyDimensionAsEventDataAttr() as a wildcard

  • withDimensionAsEventDataAttr(<dimName>) one or multiple times

For row click events all the requested dimensions will be provided. For cell clicks, the cell must be in the column of a subscribed dimension, and if so then only the cell's contents will be provided.

Main Dashboard - Chart Element

def table = api.newChartBuilder().newDataTable()

table.getOptions()
            .setTitle('Title')
            .setDisableDrilldown(true)
            // etc.

table.addSeries()
            .setLabel('Series1')
            // etc.

table.onRowClick()
            .triggerEvent(api.dashboardWideEvent('<event_name>'))
                .withDimensionAsEventDataAttr(<dimension_name1>)   // attribute_name = dim_name
                .withDimensionAsEventDataAttr(<dimension_name2>)   // attribute_name = dim_name
                ...
                // or .withAnyDimensionAsEventDataAttr() or .withDimensionAsEventDataAttr('*')

table.onCellClick()
            .triggerEvent(api.dashboardWideEvent('<event_name>'))
                .withDimensionAsEventDataAttr(<dimension_name1>)   // attribute_name = dim_name
                .withDimensionAsEventDataAttr(<dimension_name2>)   // attribute_name = dim_name
                ...
                // or .withAnyDimensionAsEventDataAttr() or .withDimensionAsEventDataAttr('*')

Main Dashboard - Embedded Element

def event_name = api.dashboardWideEvent('<event_name>')

return api  .dashboard('<dashboard_name>').showEmbedded()
            .andRecalculateOn(event_name)

            // expose the event payload
            .withEventDataAttr(<dimension_name1>).asParam(<param_name1>)
            .withEventDataAttr(<dimension_name2>).asParam(<param_name2>)
			...

The embedded dashboard's logic can read the parameters as api.input('<param_name1>') and api.input('<param_name2>').

Dashboard Display Modes

There are three ways to display the dashboard:

  • Embedded – The dashboard is embedded in the master dashboard as another portlet/dashlet.

  • Tab – The dashboard is opened in a new tab.

  • Window – The dashboard is opened in a new popup window.

The new tab or window is opened only once (i.e. on the first event) and is then reused/recalculated on every subsequent event.

 Both the tab and window can be closed automatically on a specified event. Use the option .andCloseOn(String eventName).

Available Dashboard API Methods

  • DashboardApi setParam(String paramName, Object value);

  • DashboardApi showEmbedded();

  • DashboardApi andRecalculateOn(String eventName);

  • DashboardApi openInTabOrRecalculateOn(String eventName);

  • DashboardApi openInWindowOrRecalculateOn(String eventName);

  • DashboardApi openInWindowOrRecalculateOn(String eventName);

  • DashboardApi withEventDataAttr(String attrName);

  • DashboardApi andCloseOn(String eventName);

  • DashboardApi asParam(String paramName);

For more details see the API Documentation.

Found an issue in documentation? Write to us.