Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Charts Laravel Package

laraveldaily/laravel-charts

Laravel Charts by Laravel Daily generates interactive charts for your Laravel apps from Eloquent data. Quickly build line, bar, and pie charts with minimal code, support for multiple chart libraries, and configurable options—ideal for dashboards and admin panels.

View on GitHub
Deep Wiki
Context7

Getting Started

Install with composer require laraveldaily/laravel-charts. No config publishing needed—defaults work out of the box. The first use case is rendering a simple Eloquent-backed bar chart in a controller:

use LaravelDaily\Charts\Facades\Charts;

$chart = Charts::eloquent(App\Models\User::class, 'bar')
    ->title('Users by Role')
    ->group('role')
    ->values('id');

return view('dashboard', compact('chart'));

Then in Blade: @charts('chart'). For static data (e.g., mocked metrics), use Charts::create('bar', 'chartjs') with labels() and values(). Start with the README examples—they include copy-pasteable snippets for common patterns.

Implementation Patterns

  • Eloquent-backed charts: Prefer ->eloquent(Model::class, 'type') over manual aggregation. Use ->group('column') for automatic grouping (supports relationships like ->group('team.name') as of v0.1.6).
  • Multi-dataset charts: Enable stacking with ->stacked(true) (v0.2.0+), or define conditional datasets via ->conditions([['name' => 'Paid', 'condition' => 'status = \'paid\'', 'color' => '#4CAF50']]) (v0.1.15+).
  • Time-based trends: Use ->group('created_at', 'month') with ->format('M Y') and ->timezone('America/New_York') for localized charts. Avoid manual Carbon parsing—the package handles date/datetime casting automatically.
  • Reusability: Encapsulate complex charts in service classes:
    class AnalyticsCharts {
        public static function weeklyOrders() {
            return Charts::eloquent(Order::class, 'line')
                ->group('created_at', 'week')
                ->values('total')
                ->aggregate('sum')
                ->filter(fn($q) => $q->whereNotNull('paid_at'));
        }
    }
    
  • Customization: Override defaults with ->options(['tooltips' => [...]]) for Chart.js-level control. Use ->dataset_name('Revenue') to rename auto-generated labels instead of relying on column names.

Gotchas and Tips

  • Empty dataset handling: Charts crash on null/empty values. Always validate with ->rawValues() or use ->blank('No data') (v0.1.28+) for graceful fallback.
  • Stacked option bug: Pre-v0.2.3, setting 'stacked' in raw $options fails. Always use the builder method ->stacked(true).
  • Global scopes: Soft deletes and custom scopes interfere—use ->withoutGlobalScopes() or pass an array of scopes to skip (e.g., ->withoutGlobalScopes([SoftDeletingScope::class])).
  • Aggregation quirks: ->aggregate_transform() callbacks must handle numeric types (not strings). v0.1.14 fixed type coercion—ensure your closure returns float|int, not formatted strings.
  • Relationship grouping: Ambiguous column names break SQL (e.g., name in users and teams). Prefix with table: ->group('teams.name') or alias in the query.
  • Debugging:
    • Run ->toSql() on the internal query to inspect generated SQL.
    • Use ->rawLabels() and ->rawValues() to verify data alignment.
    • For multi-dataset charts, mismatched label counts cause rendering errors—explicitly set ->labels([...]) to synchronize.
  • Limitations: Only supports Chart.js core types (bar, line, pie, doughnut). No radar/area/waterfall—implement custom JS for these.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport