Skip to content

Commit 5a7cecd

Browse files
committed
wip
1 parent f3157f7 commit 5a7cecd

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,36 @@ $svg = $sparkLine->make();
2626

2727
![](./.github/img/0.png)
2828

29+
To construct a sparkline, you'll have to pass in a collection of `Brendt\SparkLineDay` objects. This object takes two parameters: a `count`, and a `DateTimeInterface`. You could for example convert database entries like so:
30+
31+
```php
32+
$days = PostVistisPerDay::query()
33+
->orderByDesc('day')
34+
->limit(20)
35+
->get()
36+
->map(fn (object $row) => new SparkLineDay(
37+
count: $row->visits,
38+
day: Carbon::make($row->published_at_day),
39+
));
40+
```
41+
42+
In many cases though, you'll want to aggregate data with an SQL query, and convert those aggregations on the fly to `SparkLineDay` objects:
43+
44+
```php
45+
$days = DB::query()
46+
->from((new Post())->getTable())
47+
->selectRaw('`published_at_day`, COUNT(*) as `visits`')
48+
->groupBy('published_at_day')
49+
->orderByDesc('published_at_day')
50+
->whereNotNull('published_at_day')
51+
->limit(20)
52+
->get()
53+
->map(fn (object $row) => new SparkLineDay(
54+
count: $row->visits,
55+
day: Carbon::make($row->published_at_day),
56+
));
57+
```
58+
2959
### Customization
3060

3161
This package offers some methods to customize the sparkline. First off, you can pick any amount of colors and the sparkline will automatically generate a gradient from them:

0 commit comments

Comments
 (0)