Charts
{chart} draws a chart as inline SVG on the server. There is no JavaScript, so the chart prints, works where scripts do not run, and caches like any other output. A bar chart puts columns on a zero baseline; a line chart draws a line over a light wash with the last point marked.
|
PHP fragments/charts_1.php |
HTML fragments/charts_1.pad |
Result |
|---|---|---|
|
|
The first word picks the kind of chart, after the job the data has to do:
| Kind | Shows | Options |
|---|---|---|
line
|
change over time |
label, value
|
bar (or column), hbar
|
categories compared |
label, value, stacked
|
pie, donut
|
parts of a whole |
label, value
|
scatter, bubble
|
how two numbers relate |
x, y, size, label, color, trend
|
heatmap
|
patterns in a grid of two categories |
x, y, value
|
sankey
|
flows from one stage to the next |
source, target, value
|
network
|
connections |
source, target, value, layout, arrows
|
treemap, sunburst
|
a hierarchy, each part's share |
label, value, levels
|
sparkline
|
a shape the size of a word |
label, value
|
An option left out takes the first field that fits: a numeric one for a number, another one for a name.
Where the numbers come from
-
data='sales'- a {data} store, a sequence store, an array of the page's PHP, or a_datafile of that name. -
value=names the field with the number,label=the field for the axis. Without them the first numeric field is the value and the first other field the label. -
sequence='fibonacci', rows=12- the first terms of a sequence, for demo data straight away.
Several series
A list of fields in value= draws a series each - bars side by side, or on top of each other with stacked, or a line each, named at its end. A legend above the plot names them in the fixed order of the colours; eight series at most.
|
PHP fragments/charts_3.php |
HTML fragments/charts_3.pad |
Result |
|---|---|---|
|
|
Horizontal bars
hbar lays the bars down, the names on the left - for long names or many categories.
|
PHP |
HTML fragments/charts_4.pad |
Result |
|---|---|---|
|
Pie and donut
Parts of a whole: only positive values count, clockwise from twelve o'clock, a legend with each value and its share. Past eight parts the smallest are folded into one grey Other. A donut shows the total in its middle.
|
PHP |
HTML fragments/charts_5.pad |
Result |
|---|---|---|
|
Scatter and bubble
A dot per row on two numeric axes, x= and y=. color= colours the dots by a field, trend draws the least-squares line. A bubble's size= sets its area.
|
PHP fragments/charts_6.php |
HTML fragments/charts_6.pad |
Result |
|---|---|---|
|
|
Heatmap
Two categories as columns (x=) and rows (y=), each cell coloured by its value in seven steps of one hue, with the scale underneath.
|
PHP |
HTML fragments/charts_7.pad |
Result |
|---|---|---|
|
Sankey
A row is a flow from source= to target=, as wide as its value=. The columns follow the flows; flows that go round in a circle are an error.
|
PHP |
HTML fragments/charts_8.pad |
Result |
|---|---|---|
|
Network
A row is a link between two nodes. The default layout='force' pulls linked nodes together - the same data always draws the same picture - and layout='radial' sets them on a circle; arrows shows the direction.
|
PHP |
HTML fragments/charts_9.pad |
Result |
|---|---|---|
|
Treemap and sunburst
levels= lists the fields above the parts, the outermost first. A treemap nests rectangles, a sunburst rings; the colour is that of the outermost level.
|
PHP |
HTML fragments/charts_10.pad |
Result |
|---|---|---|
|
Sparklines
{sparkline} is a line chart the size of a word, without axes, to stand in a sentence or a table cell.
|
PHP |
HTML fragments/charts_2.pad |
Result |
|---|---|---|
|
Fibonacci grows fast: |
Accessible and themeable
Every chart is an image to a screen reader (role="img"), named by its title= and described by a list of its values. Every bar, point, slice, cell, flow and node carries its own tooltip; a sparkline has none. The colours are CSS custom properties - --pad-chart-series, --pad-chart-text, --pad-chart-grid, --pad-chart-surface, the categorical --pad-chart-1 to --pad-chart-8, --pad-chart-other and the heatmap's --pad-chart-heat-0 to --pad-chart-heat-6 - set on .pad-chart, and their defaults follow the page's color-scheme, light or dark.