Skip to content

Configuration

phil/svg-chart

Chart::fromConfig(array $config) reads the shape of a Chart.js configuration:

KeyRead as
typebar, line, pie or doughnut
data.labelsthe labels, texts or numbers
data.datasets[].labelthe name of a series in the legend
data.datasets[].dataone number or null per label
data.datasets[].borderColor, .backgroundColorthe colour of a series, #rrggbb
data.datasets[].backgroundColor as a listone colour per slice of a pie or a doughnut
options.plugins.title.textthe title

Every other option — animation, responsiveness, fonts, scales, plugins — sets how a browser draws the chart and is ignored. Colours are #rrggbb only: names and functions are refused rather than guessed, and so is a Dataset built directly with any other colour.

Limits

LimitValue
Labels500 (Chart::MAX_LABELS)
Series24 (Chart::MAX_DATASETS)
A label, a series name or the title200 characters (Chart::MAX_TEXT)

InvalidChart refuses a configuration that breaks a limit, misses its type or its data, or holds a value of the wrong kind; its message names the path of the value, such as data.datasets.0.data.3.

A Chart may also be built directly, with ChartType, the labels and Dataset values.