A SilverStripe GridField component that renders a uPlot line chart above or below any GridField, based on a live COUNT or SUM query against the GridField's model table.
composer require hamaka/silverstripe-gridfield-chartAdd the component to any GridField config:
use Hamaka\GridFieldChart\GridFieldUPlotGraph;
$gridField->getConfig()->addComponent(
GridFieldUPlotGraph::create(
sTargetFragment: 'before',
sSeriesLabel: 'Registrations',
iDaysBack: 30,
aExtraFilters: ['Status' => 'Active'],
)
);| Parameter | Type | Default | Description |
|---|---|---|---|
sTargetFragment |
string |
'before' |
Where to render: 'before' or 'after' |
sSeriesLabel |
string |
'Records' |
Series label shown in the chart legend |
sSumField |
?string |
null |
Field to SUM; null uses COUNT(*) |
iDaysBack |
int |
30 |
Number of days to include |
sDateField |
string |
'Created' |
Date column to group by |
aExtraFilters |
array |
[] |
Additional WHERE conditions, e.g. ['Status' => 'Active'] |
sStrokeColor |
string |
'#004e7f' |
Line colour |
sFillColor |
string |
'rgba(0,78,127,0.1)' |
Fill colour under the line |
All parameters also have fluent setters, e.g. ->setDaysBack(60).