ChartHelper
- Type
- Class
- Namespace
- craft\helpers
- Inherits
- craft\helpers\ChartHelper
- Since
- 3.0.0
Class ChartHelper
View source (opens new window)
# 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.
View source (opens new window)
Returns
# formats()
Returns the short date, decimal, percent and currency D3 formats based on Craft's locale settings
View source (opens new window)
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'.
View source (opens new window)
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 (opens new window)) – The start of the time duration to select (inclusive)$endDate
(DateTime (opens new window)) – The end of the time duration to select (exclusive)$dateColumn
(string (opens new window)) – The column that represents the date$func
(string (opens new window)) – The aggregate function to call for each date interval ('count', 'sum', 'average', 'min', or 'max')$q
(string (opens new window)) – The column name or expression to pass into the aggregate function (make sure column names are\craft\helpers\quoted
)$options
(array (opens new window)) – 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.
View source (opens new window)
Arguments
$startDate
(DateTime (opens new window))$endDate
(DateTime (opens new window))
Returns
string (opens new window) – 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
View source (opens new window)