Sparkline Column
Summary
- Sparkline Columns are AdapTable Columns which wrap AG Grid's Sparkline Charts functionality
- This allows them to be easily created, edited and saved at runtime
- Most Sparkline Columns contain an array of numbers, but advanced columns can contain Tuples and Objects
Sparkline Columns allow Sparklines to be easily displayed in Column form and then saved in Layouts.
The Sparklines are the AG Grid Sparklines provided as part of their excellent Charting package.
Sparkline Columns can be provided by developers at Design Time or created / edited by run-time users.
Hint
- Sparkline Columns created at design time must have an appropriate Array Cell Data Type
- The Column Type has to be
numberArray,tupleArrayorobjectArray
Anatomy
A Sparkline cell consists of:
- An inline mini-chart rendered from the cell's array value (numbers, tuples or objects).
- One of four chart types —
Line,Area,BarorColumn— picked at the column level. - Optional axes, point markers, tooltips and formatters, all driven by the underlying AG Grid Sparkline options.
The cell value must be an array — the column's Cell Data Type must be numberArray, tupleArray or objectArray.
Column-level options on SparklineStyle:
options— AG GridAgSparklineOptions(type, colours, axis, markers, tooltips,xKey/yKeyfor object data, etc.)Cell(optional) —CellBoxStyledrawn behind the chart (background, border, radius). When set, it claims the Cell slice from any matching Format Column
Note
Sparkline columns render on Data rows only — Group, Summary and Total rows are not supported (see Styled Columns Overview).
Sparkline Types
AG Grid Sparkline Columns can be of 4 types:
Each of these types is fully supported by AdapTable.
In the wizard, AG Grid's vertical bar sparkline is labelled Column; the horizontal bar is labelled Bar (both use type: 'bar' with different direction).
A Sparkline Column works on an array of data, rather than a single value.
Caution
To use Sparkline Columns - you must have the AG Grid SparklinesModule Module installed
Numeric Array
Sparkline data most typically takes the form of standard numeric arrays (e.g. history data).
- Overview demo — four sparkline columns share the hidden History source field (
numberArray), each with a different AG Grid chart type:- History - Line — line with markers
- History - Area — area with category axis
- History - Bar — horizontal bar
- History - Column — vertical bar (
direction: 'vertical')
- Create a Sparkline Column in the Wizard for the History column
- Click Edit First Row in the Dashboard to copy another row's history into the first row — all four sparklines update
Cell Style
Optional SparklineStyle.Cell styles the cell box behind the chart — useful when you want a bordered or tinted panel around the sparkline without affecting the chart options themselves.
- History - Line —
SparklineStyle.Cell(background, border, radius) plus a line sparkline with markers - The chart
optionsand cellCellstyling are independent — same pattern as Badge Style cell chrome
Advanced Array Types
More advanced Sparkline Columns can use complex, rather than numeric, arrays.
These arrays can be of 3 types:
Tuple Array
In a Tuple Array the data is provided in a array of arrays each of which has 2 values:
[ [14, 22], [5, 13], [19, 30] ]Note
Tuple Arrays should provide a Cell Data Type of tupleArray
Standard Object Array
AG Grid Sparklines can also receive objects.
These objects, by convention, will contain 2 properties: x and y:
[ {x: 14, y: 22}, {x: 5, y: 13}, {x: 19, y: 30} ]Note
Standard Object Arrays should provide a Cell Data Type of objectArray
Non-Standard Object Array
AG Grid Sparklines can also be created with objects that do not have the standard x and y properties.
However they are still required to contain 2 properties, which are needed for the 2 axes:
[ {xVal: 14, yVal: 22}, {xVal: 5, yVal: 13}, {xVal: 19, yVal: 30} ]Note
Non-Standard Object Arrays should also provide a Cell Data Type of objectArray
- Three sparkline columns show the same history data in non-numeric array shapes:
- History - Tuple —
tupleArraydata, vertical bar (Column) sparkline - History - Object — standard
{ x, y }objects, area sparkline - History - Object Non Standard — custom property names via
xKey/yKeyon the line sparkline
- History - Tuple —
Sparkline Calculated Columns
Sparkline Columns can be used by Calculated Columns to render Array data.
Most typically the Calculated Column will use the TO_ARRAY Expression Function to create the data.
- Two Calculated Columns use
TO_ARRAYand render as sparklines:- Statistics — area sparkline over
[Open PRs, Closed PRs, Open Issues, Closed Issues] - Github — horizontal bar sparkline over
[GitHub Stars, GitHub Watchers × 30]
- Statistics — area sparkline over
Defining Sparkline Columns
Sparkline Styles are provided at design-time through Styled Column Initial State.
Developer Guide
Providing a Sparkline Style in Styled Column State
const initialState: InitialState = {
StyledColumn: {
StyledColumns: [
{
ColumnId: 'historyLine',
Name: 'History Line',
SparklineStyle: {
options: {
type: 'line',
stroke: 'rgb(124, 255, 178)',
strokeWidth: 2,
marker: { enabled: true, size: 3 },
},
Cell: {
BackColor: 'rgba(255, 255, 255, 0.06)',
BorderColor: 'rgba(124, 255, 178, 0.35)',
BorderRadius: 6,
},
},
},
],
},
};ColumnId— must reference a column withnumberArray,tupleArrayorobjectArraydata typeName— unique styled column nameSparklineStyle— wrapper for chart options and optional cell chrome
SparklineStyle.options is passed through to AG Grid — set type (line, area, bar), colours, axis, markers, tooltips, and for object arrays xKey / yKey when properties are not x / y.
Find Out More
See AG Grid Sparklines for the full options surface.
SparklineStyle.Cell — optional CellBoxStyle behind the chart. When set, matching Format Column cell-box properties are stripped for that column.
Creating Sparkline Columns
Sparkline Styles can be created at run-time using the Styled Column UI Wizard.
UI Step by Step Guide
Creating a Sparkline Style using the Styled Column Wizard
FAQ
Can we export Sparkline Columns when using the VisualExcel Report Format? Not currently, but we plan to look at this in a forthcoming release
I cannot see the Sparkline Column in my Grid?
Make sure you have the AG Grid SparklinesModule Module installed
Why are there no columns visible in the Wizard when I try to create a sparkline?
AdapTable will only display columns which have an appropriate Cell Data Types for a Sparkline Column.
This needs to be one of numberArray, tupleArray or objectArray