ChartHelper ​
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\ChartHelper
- Since
- 3.0.0
Class ChartHelper
Public Methods ​
Method | Description |
---|---|
dateRanges() | Returns the predefined date ranges with their label, start date and end date. |
formats() | Returns the short date, decimal, percent and currency D3 formats based on Craft's locale settings |
getRunChartDataFromQuery() | Returns the data for a run chart, based on a given DB query, start/end dates, and the desired time interval unit. |
getRunChartIntervalUnit() | Returns the interval unit that should be used in a run chart, based on the given start and end dates. |
shortDateFormats() | Returns the D3 short date formats based on Yii's short date format |
dateRanges()
​
Returns the predefined date ranges with their label, start date and end date.
Returns ​
formats()
​
Returns the short date, decimal, percent and currency D3 formats based on Craft's locale settings
Returns ​
getRunChartDataFromQuery()
​
Returns the data for a run chart, based on a given DB query, start/end dates, and the desired time interval unit.
The query’s SELECT clause should already be set to a column aliased as value
. The $options array can override the following defaults:
intervalUnit
- The time interval unit to use ('hour', 'day', 'month', or 'year'). By default, a unit will be decided automatically based on the start/end date duration.categoryLabel
- The label to use for the chart categories (times). Defaults to "Date".valueLabel
- The label to use for the chart values. Defaults to "Value".valueType
- The type of values that are being plotted ('number', 'currency', 'percent', 'time'). Defaults to 'number'.
Arguments ​
$query
(craft\db\Query) – The DB query that should be used. It will be executed for each time interval, with additional conditions on the $dateColumn, via craft\db\Query::scalar().$startDate
(DateTime) – The start of the time duration to select (inclusive)$endDate
(DateTime) – The end of the time duration to select (exclusive)$dateColumn
(string) – The column that represents the date$func
(string) – The aggregate function to call for each date interval ('count', 'sum', 'average', 'min', or 'max')$q
(string) – The column name or expression to pass into the aggregate function (make sure column names are\craft\helpers\quoted
)$options
(array) – Any customizations that should be made over the default options
Returns ​
Throws ​
getRunChartIntervalUnit()
​
Returns the interval unit that should be used in a run chart, based on the given start and end dates.
Arguments ​
Returns ​
string – The unit that the chart should use ('hour', 'day', 'month', or 'year')
shortDateFormats()
​
Returns the D3 short date formats based on Yii's short date format