Skip to content

classes_lib_controls_chartjs3.class

Daniel Spors edited this page Dec 19, 2023 · 2 revisions

Classes in file lib/controls/chartjs3.class.php

class ChartJS3

Represents a Chart.js chart

Extends: Control » Renderable

addPieData

Appends data for a Pie chart.

Definition: public function addPieData($name_value_pairs)

Returns: static

Parameters:

  • array $name_value_pairs key-value pairs of data

addPlugin

Adds a plugin to be loaded.

Definition: public function addPlugin($name)

Returns: static

Parameters:

  • string $name Plugin name

Bar

SHORTCUT Create a Bar chart

dataset

Get/Set dataset related configuration.

Definition: public function dataset($index, $name, $value=null)

Returns: mixed Returns $this is value is given, else the data requested

Parameters:

  • int $index Datase index

  • string $name Config name

  • mixed $value Optional value

DatePoint

INTERNAL Handler for points of type Date

Doughnut

SHORTCUT Create a Doughnut chart

eachSeries

Iterates series.

Definition: public function eachSeries($callback)

Returns: static

Parameters:

  • callable $callback Callback that received each searies

fill

Fill the chart with data using a callback.

Definition: public function fill($seriesCallback)

Returns: $this

Parameters:

  • callable $seriesCallback Callback that will receive the series name and must return an array with data

fillGaps

Fills all series with contiguous points.

Definition: public function fillGaps($increment)

Returns: $this

Parameters:

  • \Closure|int $increment An integer value or a callback, that receives a X-value and returns the next

getAjaxData

Prepare the data to be ajax usable.

Definition: public function getAjaxData()

Returns: array The data

legend

Gets/Sets the legend.

Definition: public function legend($name, $value=null)

Returns: mixed Returns $this is value is given, else the data requested

Parameters:

  • string $name Name

  • mixed $value Optional value

Line

SHORTCUT Create a Line chart

MultiSeriesTime

SHORTCUT Create a multi-series time chart

onMissingPoint

Sets a handler to be called when points are missing. This can be the case when harmonizing data (so that every series has the same X-Values) or when is called.

Definition: public function onMissingPoint($missingPointCallback)

Returns: $this

Parameters:

  • \Closure $missingPointCallback Callback function that receives series_name, x and xval parameters and must return a point

opt

Sets or gets an option if you specify a $value will set it and retunr $this. else will return the option value

Definition: public function opt($name, $value=null)

Returns: mixed If setting an option returns $this, else returns the option value

Parameters:

  • string $name option name

  • mixed $value option value or null

Pie

SHORTCUT Create a Pie chart

PreRender

OVERRIDE Control::PreRender

scales

Get/Set scale related configuration.

Definition: protected function scales($scaleId, $name, $value=null)

Returns: mixed Returns $this is value is given, else the data requested

Parameters:

  • $scaleId NOT DOCUMENTED

  • string $name Config name

  • mixed $value Optional value

scaleX

SHORTCUT ChartJS3::scales

scaleY

SHORTCUT ChartJS3::scales

setChartData

Sets data.

Definition: public function setChartData(iterable $data, string $x_value_row, $pointType, $pointdatacallback=false)

Returns: $this

Parameters:

  • iterable $data The actual data

  • string $x_value_row Name of the field that represents the series name

  • string $pointType Optional classname of the Point handler

  • Closure $pointdatacallback Optional closure receiving $row,$series,$x_value_row_name

setColorRange

Sets a ColorRange for the chart.

Definition: public function setColorRange($range)

Returns: $this

Parameters:

  • \ScavixWDF\Base\Color\ColorRange $range Range of colors

setColors

Sets the chart colors.

Definition: public function setColors($colors)

Returns: $this

Parameters:

  • array $colors Array of color valus

setDelayed

Sets if the chart should load it's data via AJAX.

Definition: public function setDelayed($url, $refresh_interval)

Returns: static

Parameters:

  • string $url The data URL

  • int $refresh_interval Optional interval to refresh the data (default: -1 = off)

setNamedColors

Sets the named chart colors.

Definition: public function setNamedColors($colors)

Returns: $this

Parameters:

  • array $colors Associative array of color valus

setPercentAxesY

Sets Y-Axis to be a percentual scale.

Definition: public function setPercentAxesY()

Returns: $this

setPieData

Sets data for a Pie chart.

Definition: public function setPieData($name_value_pairs)

Returns: static

Parameters:

  • array $name_value_pairs key-value pairs of data

setSeries

Sets series names.

Definition: public function setSeries($seriesNames, $append=false)

Returns: $this

Parameters:

  • array $seriesNames Series names

  • bool $append If true, series will be appended, else existing will be replaced

setSeriesData

Sets series data.

Definition: public function setSeriesData(iterable $data, string $series_row, string $x_value_row, string $y_value_row, $pointType, $pointdatacallback=false)

Returns: $this

Parameters:

  • iterable $data The actual data

  • string $series_row Name of the field with the series name

  • string $x_value_row Name of the field with the x-values

  • string $y_value_row Name of the field with the y-values

  • callable|string $pointType Optional classname of the Point handler

  • Closure $pointdatacallback Optional closure receiving $row,$series,$series_row_name,$x_value_row_name,$y_value_row_name

setSeriesOrder

Defines the drawing order of the data series.

Definition: public function setSeriesOrder($names)

Returns: static

Parameters:

  • array $names Seriesnames in correct order

setStacked

Sets this chart to be stacked.

Definition: public function setStacked()

Returns: $this

setTimeAxesX

Sets the xAxes to be a time-scale.

Definition: public function setTimeAxesX($unit=false)

Returns: $this

Parameters:

  • string $unit OPtional unit specifier

setTitle

Sets the chart title.

Definition: public function setTitle($text)

Returns: $this

Parameters:

  • string $text Title

setType

Sets the chart type.

Definition: public function setType($type)

Returns: $this

Parameters:

  • string $type The type name

StackedBar

SHORTCUT Create a Stacked-Bar chart

StrPoint

INTERNAL Handler for points of type String

TimePoint

INTERNAL Handler for points of type Time

tooltip

Gets/Sets the tooltip.

Definition: public function tooltip($name, $value=null)

Returns: mixed Returns $this is value is given, else the data requested

Parameters:

  • string $name Name

  • mixed $value Optional value

WeekPoint

INTERNAL Handler for points of type Week

xLabels

Gets/Sets X-Axes labels.

Definition: public function xLabels($labels=null)

Returns: mixed $this is lables is given, else the data requested

Parameters:

  • array $labels Optional labels as array
Clone this wiki locally