myCred_Chart

Description

This object is used to generate the chart HTML canvas element and construct the required JavaScript data for Chart.js. Used by the Statistics add-on. While the method only returns an empty HTML canvas element, the actual chart JavaScript data is populated using the $mycred_charts global. The statistics add-on uses this global to render the actual data in the footer of your website.

Available since version 1.8

Interacting with Object

This object should be accessed using the mycred_create_chart function.

Object properties

Note that the constructor class will auto populate these values when the class is constructed.

Property Type Description
myCRED_Chart Object (
public $args array Global attributes for the chart we want to render.
public $now int The current UNIX timestamp.
public $point_types array An associative array of point type keys and myCRED_Point_Type objects.
public $point_colors array An associative array of point type keys and the colors saved to be used for each type.
public $date_format string The date format set in our WordPress settings.
public $time_format string The time format set in our WordPress settings.
)

Global Arguments:

Key Type Default Description
type string pie The chart type we plan on constructing.
color string or array - Option to set the color to use. This can be a string containing one color (mainly used for line charts) or an array containing a color for positive values and one for negative.
animate bool Add-on Settings If the chart should be animated or not. Will enforce the default setting that you chose in your add-on settings.
bezier bool Add-on Settings If the chart should use bezier curves for lines or not. Will enforce the default setting that you chose in your add-on settings.
x_labels bool TRUE If the labels for the X axis should be shown or not. Some references have long names and this can cause the chart to render small with long names.
label_max int 20 The maximum character length of the X axis label.
legend bool TRUE If the chart legend should be shown or not.
title string or array - Option to set a title for the chart. You can also provide an array of settings for more control of the rendered title.
width int or string - The width of the canvas element. By default the element will be full width.
height int or string 250 The height of the canvas element.

Object Methods

public function __construct( $args = array() ) {
Description: Constructs the objects and populates the object properties. It also parses the global arguments you provided.
Variable Type Required Description
$args array No An associative array of global arguments to use for the chart we are about to render.
}
public function apply_defaults( $args = array() ) {
Description: This menthod will apply the default arguments to the arguments provided when the object was constructed.
Variable Type Required Description
$args array No An associative array of global arguments.
}
public function parse_args( $args = array() ) {
Description: Parses your given global arguments, ensuring that valid values are used.
Variable Type Required Description
$args array No An associative array of global arguments.
}
public function get_chart_options() {
Description: Returns the chart options object.
}
public function generate_element_id() {
Description: Returns a unique ID to be applied on the canvas element.
}
public function get_canvas_styling() {
Description: Returns the CSS styling that needs to be applied to the canvas element based on our global arguments.
}
public function get_reference_label( $reference = '' ) {
Description: Returns the label for the given reference id.
Variable Type Required Description
$reference string Yes The reference key.
}
public function generate_canvas( $type = '', $input = array() ) {
Description: Returns the chart options object.
Variable Type Required Description
$type string Yes The chart type we want to use.
$input array Yes An array of data to process.
}
public function pie_chart( $input = array() ) {
Description: Generates a pie chart based on the provided $input data.
Variable Type Required Description
$input array Yes An array of data to process.
}
public function doughnut_chart( $input = array() ) {
Description: Generates a doughnut chart based on the provided $input data.
Variable Type Required Description
$input array Yes An array of data to process.
}
public function line_chart( $input = array() ) {
Description: Generates a line chart based on the provided $input data.
Variable Type Required Description
$input array Yes An array of data to process.
}
public function bar_chart( $input = array() ) {
Description: Generates a bar chart based on the provided $input data.
Variable Type Required Description
$input array Yes An array of data to process.
}
public function polar_chart( $input = array() ) {
Description: Generates a polar area chart based on the provided $input data.
Variable Type Required Description
$input array Yes An array of data to process.
}
public function radar_chart( $input = array() ) {
Description: Generates a radar chart based on the provided $input data.
Variable Type Required Description
$input array Yes An array of data to process.
}

Object Example

myCRED_Chart Object
(
    [args] => Array
        (
            [type] => pie
            [color] => 
            [animate] => true
            [bezier] => true
            [x_labels] => true
            [legend] => true
            [title] => 
            [width] => 
            [height] => 250
            [label_max] => 20
        )
    [point_types] => Array
        (
            [mycred_default] => myCRED_Point_Type Object
                (
                    [cred_id] => mycred_deed
                    [singular] => Deed
                    [plural] => Deeds
                    [prefix] => 
                    [suffix] => de.
                    [format] => Array
                        (
                            [type] => bigint
                            [decimals] => 0
                            [separators] => Array
                                (
                                    [decimal] => .
                                    [thousand] => ,
                                )

                        )
                    [lowest_value] => 1
                )
        )
    [point_colors] => Array
        (
            [mycred_default] => Array
                (
                    [positive] => #dedede
                    [negative] => #ddd000
                )
        )
    [date_format] => Y-m-d
    [time_format] => H:i
)

}