Moodle APIs  3.8
Moodle 3.8.6 (Build: 20201109)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
core\chart_base Class Reference

Chart base class. More...

Inheritance diagram for core\chart_base:
renderable core\chart_bar core\chart_line core\chart_pie

Public Member Functions

 __construct ()
 Constructor. More...
 
 add_series (chart_series $serie)
 Add a series to the chart. More...
 
 get_labels ()
 Get the labels of the X axis. More...
 
 get_series ()
 Get the series. More...
 
 get_title ()
 Get the title. More...
 
 get_type ()
 Get the chart type. More...
 
 get_xaxes ()
 Get the X axes. More...
 
 get_xaxis ($index=0, $createifnotexists=false)
 Get an X axis. More...
 
 get_yaxes ()
 Get the Y axes. More...
 
 get_yaxis ($index=0, $createifnotexists=false)
 Get a Y axis. More...
 
 jsonSerialize ()
 Serialize the object. More...
 
 set_labels (array $labels)
 Set the chart labels. More...
 
 set_title ($title)
 Set the title. More...
 
 set_xaxis (chart_axis $axis, $index=0)
 Set an X axis. More...
 
 set_yaxis (chart_axis $axis, $index=0)
 Set an Y axis. More...
 

Protected Member Functions

 set_defaults ()
 Set the defaults for this chart type. More...
 
 validate_axis ($xy, chart_axis $axis, $index=0)
 Validate an axis. More...
 

Protected Attributes

string[] $labels = []
 The labels for the X axis when categorised.
 
chart_series[] $series = []
 The series constituting this chart.
 
string $title = null
 The title of the chart.
 
chart_axis[] $xaxes = []
 The X axes.
 
chart_axis[] $yaxes = []
 The Y axes.
 

Detailed Description

Chart base class.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Constructor & Destructor Documentation

◆ __construct()

core\chart_base::__construct ( )

Constructor.

Must not take any argument.

Most of the time you do not want to extend this, rather extend the method self::set_defaults to set the defaults on instantiation.

Member Function Documentation

◆ add_series()

core\chart_base::add_series ( chart_series  $serie)

Add a series to the chart.

Parameters
chart_series$serieThe serie.

◆ get_labels()

core\chart_base::get_labels ( )

Get the labels of the X axis.

Return values
string[]

◆ get_series()

core\chart_base::get_series ( )

Get the series.

Return values
chart_series[]

◆ get_title()

core\chart_base::get_title ( )

Get the title.

Return values
string

◆ get_type()

core\chart_base::get_type ( )

Get the chart type.

Return values
string

◆ get_xaxes()

core\chart_base::get_xaxes ( )

Get the X axes.

Return values
chart_axis[]

◆ get_xaxis()

core\chart_base::get_xaxis (   $index = 0,
  $createifnotexists = false 
)

Get an X axis.

Parameters
int$indexThe index of the axis.
bool$createifnotexistsWhen true, create an instance of the axis if none exist at this index yet.
Return values
chart_axis

◆ get_yaxes()

core\chart_base::get_yaxes ( )

Get the Y axes.

Return values
chart_axis[]

◆ get_yaxis()

core\chart_base::get_yaxis (   $index = 0,
  $createifnotexists = false 
)

Get a Y axis.

Parameters
int$indexThe index of the axis.
bool$createifnotexistsWhen true, create an instance of the axis if none exist at this index yet.
Return values
chart_axis

◆ jsonSerialize()

core\chart_base::jsonSerialize ( )

Serialize the object.

Return values
array

Reimplemented in core\chart_pie, core\chart_line, and core\chart_bar.

◆ set_defaults()

core\chart_base::set_defaults ( )
protected

Set the defaults for this chart type.

Child classes can extend this to set default values on instantiation.

In general the constructor could be used, but this method is here to emphasize and self-document the default values set by the chart type.

Return values
void

Reimplemented in core\chart_bar.

◆ set_labels()

core\chart_base::set_labels ( array  $labels)

Set the chart labels.

Parameters
string[]$labelsThe labels.

◆ set_title()

core\chart_base::set_title (   $title)

Set the title.

Parameters
string$titleThe title.

◆ set_xaxis()

core\chart_base::set_xaxis ( chart_axis  $axis,
  $index = 0 
)

Set an X axis.

Note that this will override any predefined axis without warning.

Parameters
chart_axis$axisThe axis.
int$indexThe index of the axis.

◆ set_yaxis()

core\chart_base::set_yaxis ( chart_axis  $axis,
  $index = 0 
)

Set an Y axis.

Note that this will override any predefined axis without warning.

Parameters
chart_axis$axisThe axis.
int$indexThe index of the axis.

◆ validate_axis()

core\chart_base::validate_axis (   $xy,
chart_axis  $axis,
  $index = 0 
)
protected

Validate an axis.

We validate this from PHP because not doing it here could result in errors being hard to trace down. For instance, if we were to add axis at keys without another axis preceding, we would effectively contain the axes in an associative array rather than a simple array, and that would have consequences on serialisation.

Parameters
string$xyAccepts x or y.
chart_axis$axisThe axis to validate.
index$indexThe index of the axis.

The documentation for this class was generated from the following file: