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

array (opens new window)

# formats()

Returns the short date, decimal, percent and currency D3 formats based on Craft's locale settings

View source (opens new window)

Returns

array (opens new window)

# 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

Returns

array (opens new window)

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

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)

Returns

array (opens new window)