llabbasmkhll/laravel-sparkline
Composer 安装命令:
composer require llabbasmkhll/laravel-sparkline
包简介
generate small chart and sparklines in your laravel app
README 文档
README
Generate small chart and sparklines in your laravel app like a breeze.
this package helps you to plot prices of stock ,currencies ,crypto, etc, into an image in your laravel app.
it uses image intervention and PHP gd to generate the image.
Installation
composer require abbaudo/laravel-sparkline
Usage
to use sparkline all you have to is providing the numbers that you want to plot to data function and render the chart like below:
$metrics = [76, 80, 50, 62, 32, 55, 42, 5, 10, 2, 22, 5, 6, 26, 25, 55, 40, 32, 55, 42, 5, 10, 2, 22, 56]; return Sparkline::data($metrics)->render()->response('png');
this will generate an sparkline like this:

Note
render() will return an Intervention\Image object. more information in image intervention.
if your too lazy to read intervention docs simply use ->response('png') to return the sparkline to the browser.
or ->save('public/fou.jpg') to save the sparkline.
Customization
Color
line
set the color of the sparkline by color function. by defult its yellow.
$red = 250; $green = 100; $blue = 100; $alpha = 1; Sparkline::data($metrics)->color($red, $green, $blue, $alpha)->render()->response('png');
background
set the background color by backgorund function. by defult its transparent.
$red = 250; $green = 70; $blue = 70; $alpha = 0.2; Sparkline::data($metrics)->backgound($red, $green, $blue, $alpha)->render()->response('png');
fill
to fill the sparkline use fill function. by defult its transparent.
$red = 250; $green = 70; $blue = 70; $alpha = 0.2; Sparkline::data($metrics)->fill($red, $green, $blue, $alpha)->render()->response('png');
Thickness
set line thikness by calling thickness like so :
Sparkline::data($metrics)->thikness(3)->render()->response('png');
Fade
by defult sparklines made with faded color in the begining of the line. to customize it use fade.
Sparkline::data($metrics)->fade(0.2)->render()->response('png');

1.0 to maximum fade and 0.0 to remove the fade
Size
to change the size of the sparkline use size. the defult size is 80px for height and 200px for width.
$width = 500; $height = 100; Sparkline::data($metrics)->size($width, $height)->render()->response('png');
use width and heigt to change the size seperatly.
Sparkline::data($metrics)->width(400)->render()->response('png'); Sparkline::data($metrics)->height(100)->render()->response('png'); Sparkline::data($metrics)->width(300)->height(80)->render()->response('png');
Example
SparklineController.php
class SparklineController extends Controller { public function index(Currency $currency) { $metrics = Coingecko::getMetrics($currency->code); $sparkline = Sparkline::data($metrics); if ($metrics[0] - end($metrics) > 0) { $sparkline->color(250, 100, 100); } elseif ($metrics[0] - end($metrics) < 0) { $sparkline->color(100, 250, 100); } return $sparkline->render()->response('png'); } }
web.php
Route::get('/currencies/{currency}/sparkline.png', [SparklineController::class, 'index'])->name('currencies.sparkline');
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Abbas mkhzomi - Telegram@abbaudox - amkhzomi@gmail.com
Project Link: https://github.com/abbaudo/laravel-sparkline
llabbasmkhll/laravel-sparkline 适用场景与选型建议
llabbasmkhll/laravel-sparkline 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 161 次下载、GitHub Stars 达 8, 最近一次更新时间为 2022 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 llabbasmkhll/laravel-sparkline 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 llabbasmkhll/laravel-sparkline 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 161
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-20




