sc_widget_data('dataName')

The sc_widget_data() macro returns data from an Index widget, allowing access to comparative and statistical values defined in the widget’s configuration.

It can be used to customize the widget’s content and appearance based on runtime-calculated data, such as percentage variation or difference between periods.

Parameter

This macro receives a single parameter, which must be the name of the data you want to retrieve.

Example of use:

sc_widget_data('value')

Available parameters

Parameter Description
value Main value of the current period.
period Current period configured in the widget (e.g., current month, week, etc.).
last_value Value of the previous period.
last_period Label of the previous period (e.g., previous month, last week, etc.).
difference Difference between the two periods (value - last_value).
variation Percentage variation between periods (comparison between value and last_value).

Example

$dif = sc_widget_data('difference');

if ($dif < 0) {
  sc_widget_config([
    'background-color' => '#ffdddd',
    'border-color' => '#cc0000',
    'legend' => 'Performance below the previous period',
  ]);
} else {
  sc_widget_config([
    'background-color' => '#ddffdd',
    'border-color' => '#00cc00',
    'legend' => 'Improved compared to the previous period',
  ]);
}

In the example above, the sc_widget_data() macro retrieves the difference between periods. Based on that value, the widget’s appearance is dynamically adjusted.