KPIComponent

class KPIComponent
setTimestampExpression($timestampExp, $kpiTimestampOptions)

The timestamp expression is a SQL Expression which usually corresponds to a DATETIME column in your DataSource.

Parameters:
  • $timestampExp (DBExpression) – The timestamp expression
  • $kpiTimestampOptions (KPITimestampOptions) –
setValueExpression($valueExp, $kpiValueOptions)

The Value Expression is a SQL Expression which is used to determine the value of the KPI that will be displayed to your users.

Parameters:
  • $valueExp (DBExpression) – The value expression
  • $kpiValueOptions (KPIValueOptions) –
setValueFromSQLQuery($queryString, $options)

Set the value from a SQL Query, for when the value of the KPI cannot be determined from timestamp and value expressions.

Please note the following:

  1. The Query will be executed as provided, and will not be modified. This might have some security considerations
  2. KPIs with values from SQL Query cannot be filtered, or have a drill down from another component.
  3. If you do not add a “LIMIT” Clause to the Query, and there are too many rows, PHP might run out of memory
  4. The first column of the first row will be taken as the KPI Value. If you wish to override this, please set the KPIValueFromQueryOptions::$valueColumn
Parameters:
  • $queryString (string) – The SQL Query to execute for the KPI
  • $options (KPIValueFromQueryOptions) – Options to customize how the query’s data is used
countDistinct($valueExp)

Count the number of distinct occurences of the value expression.

Parameters:
  • $valueExp (DBExpression) – the value expression
setStaticCurrentValue($value, $options)

Set a static current value for KPI.

Parameters:
  • $value (number) – The value that will be displayed.
  • $options (KPIValueOptions) –
setStaticPastValues($values)

Set static past values of a KPI.

These values will be displayed in the miniature spark chart below the KPI Value that is displayed on the screen.

Parameters:
  • $values (array) – an array of values to be displayed.
addTarget($value, $name)

Adds a target that will be marked on the gauge

Parameters:
  • $value (number) – The value at which the target is marked
  • $name (string) – The name of the target
setSparkLineOptions()
getOptionClassName()
setColorRanges($colorRanges)

Set the ColorRange object.

This object specifies the colors to be used while displaying the gauge in Gauge KPIs

Parameters:
  • $colorRanges (ColorRange) – The Color Range object
setKeyPoints($keyPoints, $colors)

Set the “Key Points”. The Key Points are used to divide the gauge and show a different color in each division.

If you do not specify the colors, they will be automatically generated according to the theme.

Parameters:
  • $keyPoints (array) – An array of numbers used to demarkate the gauge
  • $colors (array) – An optional array of colors which
setKeyPercentages($keyPoints, $colors)

Set the “Key Points”. The Key Points are used to divide the gauge and show a different color in each division.

However, if the Max/Min of the gauge vary, you can set key percentages instead, which are automatically converted into key points based on the limits of the gauge.

If you do not specify the colors, they will be automatically generated according to the theme.

Parameters:
  • $keyPoints (array) – An array of numbers used to demarkate the gauge
  • $colors (array) – Which colors to show for each section of the gauge
addSQLWhere($exp, $boolOperand)

Add a SQL WHERE clause to this component.

1. The contents of the expression are not Escaped or binded to prepared queries. Using this function in a non-secure manner may open up your dashboard to SQL Injection vulnerabilities. 2. This condition is only applied to this specific component, not to other components.

Parameters:
  • $exp (string) – The expression to add to the SQL Queries
  • $boolOperand (string) – The boolean operand for the condition. (“AND”/”OR)
sortOn($exp, $sortOrder)

Sort the data in the component based on a particular expression. This is equivalent to having an “ORDER BY” clause in your SQL Queries.

However, this function might not work as expected in components which have data aggregated and grouped by another column. If this is the case, you should use the in-built sorting functionality of the component itself.

1. The contents of the expression are not Escaped or binded to prepared queries. Using this function in a non-secure manner may open up your dashboard to SQL Injection vulnerabilities. 2. This condition is only applied to this specific component, not to other components.

Parameters:
  • $exp (string) – The expression to sort by
  • $sortOrder (string) – The Sort order (“ASC”/”DESC”)
limitTo($exp, $sortOrder)

Limit the data in the component based on a particular expression. This is equivalent to having an “LIMIT” clause in your SQL Queries.

Parameters:
  • $exp (int) – The number of records to take
  • $sortOrder (int) – The number of records to skip
addCondition($expression, $comparison, $value, $boolOperand)

Add a condition to the component. This is similar to having a “WHERE” clause in your SQL Query, but there are a few differences:

1. The $value parameter is protected against SQL Injection attacks so you do not need to worry about escaping the value. 2. There are specific comparisons that you can perform

The comparison operators you can use are:

  • Equality: “eq”, “==”, “isequalto”, “equals”, “equalto”, “equal”
  • Inequality: “neq”, ”!=”, “isnotequalto”, “notequals”, “notequalto”, “notequal”, “ne”
  • Less than: “lt”, “<”, “islessthan”, “lessthan”, “less”
  • Less than or equal to: “lte”, “<=”, “islessthanorequalto”, “lessthanequal”, “le”
  • Greater Than: “gt”, “>”, “isgreaterthan”, “greaterthan”, “greater”
  • Greater Than or Equal To: “gte”, “>=”, “isgreaterthanorequalto”, “greaterthanequal”, “ge”
  • Starts with: “startswith”
  • Ends wit: “endswith”
  • Contains: “contains”
Parameters:
  • $expression (string) – The column or expression to filter
  • $comparison (string) – The comparison operator
  • $value (mixed) – The value to compare against
  • $boolOperand (string) – The boolean operand (AND/OR)
addInitialCondition($expression, $comparison, $value, $boolOperand)

Add a condition which is only applied if there isn’t a drilldown.

Identical behavior to Component::addCondition

Parameters:
  • $expression (string) – The column or expression to filter
  • $comparison (string) – The comparison operator
  • $value (mixed) – The value to compare against
  • $boolOperand (string) – The boolean operand (AND/OR)
setDataSource($datasource)

Set the DataSource for this component.

The DataSource contains information on where to access the data to display in the component.

Parameters:
setCaching()

This function is Not Supported currently

addPostProcessRowCallback($callback)

After processing data (querying, fetching, filtering, etc), you can register a callback to be called with each row. Note that the callback can modify any row and return the final row.

Let’s say that you have a pie chart, but your database has values 0 and 1. You want to rewrite labels 0 => “Not Available” and 1 => “Available” you can add a callback like this

$pieChart->addPostProcessCallback('rewrite_labels');

function rewrite_labels ($row, $sourceComponent) { if($row[‘rfLabels’] === ‘0’) { $row[‘rfLabels’] = “Not Available”; } else if($row[‘rfLabels’] === ‘1’) { $row[‘rfLabels’] = “Available”; } return $row; // Don’t forget this }

Parameters:
  • $callback (function) – A function or name of function to execute
log($message)
Parameters:
  • $message (string) – The message to log
setOption()

Sets one or more options for this component.

You can call setOption in the following ways:

  1. With two params:

$component->setOption(‘caption’, “Hello!”);

  1. As an array of key-value pairs

$component->setOption (array( ‘caption’ => “Hello”, ‘numberPrefix’ => ‘$’ ));

3. As an object of the Options class for the component you’re using. for example, if you’re using it to configure a chart component, you can say

$opt = new ChartOptions();
$opt->caption = "hello";
$opt->numberPrefix = "$";
$component->setOption($opt);
setCaption($caption)

Set the caption for this component.

Parameters:
  • $caption (string) –
setPlaceholder(string)
Parameters:
  • string ($caption) – caption
setWidth($width)

Set the width class for this component.

The width can be 1 to 4.

See dimensions for more information on this

Parameters:
  • $width (int) – The width in Units of 1 to 4
setHeight($width)

Set the height class for this component.

See dimensions for more information on this

Parameters:
  • $width (int) – The height in Units
setDimensions($width, $height)

Set the dimensions for this component

The width can be between 1 to 4.

See dimensions for more information.

Parameters:
  • $width (int) – The width
  • $height (int) – The height
getID()
property ID

The ID of the object.

Every instance of the inherited cass created in a request will have a different ID

However, IDs are sequentially generated. So It’s certain that a script with multiple instances of a class

Type: string
Default: “(unset)”

Start building interactive, mobile-friendly Dashboards in PHP. See DemosDownload