Weave 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

Larapex Charts Laravel Package

gigerit/larapex-charts

gigerit/larapex-charts is a Laravel wrapper for ApexCharts that lets you build interactive, responsive charts in PHP and Blade. Define datasets, labels, and chart types with a fluent API, then render the container and script directly in your views—no hand-written JavaScript required.

View on GitHub
Deep Wiki
Context7

Getting Started

gigerit/larapex-charts is a thin Laravel wrapper around ApexCharts.js: you build a chart object in PHP, it emits a <div> container plus a JS initialiser. Nothing is rendered server-side, so all interactivity/tooltips stay client-side.

  1. Install and publish config:
    composer require gigerit/larapex-charts
    php artisan vendor:publish --tag=larapex-charts-config
    
    config/larapex-charts.php holds the ApexCharts CDN URL, default colors, and font family. Check the CDN entry first if charts render blank.
  2. Load the ApexCharts JS once in your layout (either from the config CDN or a self-hosted asset):
    <script src="{{ config('larapex-charts.cdn') }}"></script>
    
  3. Build a chart in a controller and hand it to the view:
    $chart = (new LarapexChart)
        ->setType('line')
        ->setTitle('Revenue')
        ->setXAxis($months)                       // flat array of labels
        ->setDataset([['name' => 'Revenue', 'data' => $totals]]);
    
  4. Render in Blade — container first, script after the library and after the DOM node:
    {!! $chart->container() !!}
    @push('scripts') {!! $chart->script() !!} @endpush
    

First use case to build: a dashboard card where a single Eloquent aggregate (->selectRaw('SUM(...) as total')->groupBy('month')) feeds setXAxis()/setDataset(). If that works end-to-end, everything else is option plumbing.

Implementation Patterns

Dedicated chart classes. Don't build charts inline in controllers. Create app/Charts/*.php with a build(): LarapexChart method (or a Chartable interface) so a chart can be reused across a dashboard, an export, and a JSON API without duplication. Inject them via the container.

Facade factories for boilerplate. LarapexChart::lineChart(), areaChart(), barChart(), pieChart(), donutChart(), radialChart(), polarAreaChart(), heatMapChart(), radarChart() pre-set the type. Use them and then chain options, rather than repeating setType() everywhere.

Pie/donut differ from cartesian. For pie/donut/radial/polarArea you set a flat setDataset([...]) of values and a matching setLabels([...]); ['name' => ..., 'data' => ...] series arrays are for line/area/bar/radar. Getting this backwards produces an empty or one-slice chart with no error.

Blade component wrapper. Wrap container() + script() in an anonymous component (<x-chart :chart="$chart" />) that pushes to a scripts stack. This keeps layouts clean and guarantees ordering in one place:

@props(['chart'])
<div {{ $attributes }}>{!! $chart->container() !!}</div>
@once @push('scripts') <script src="{{ config('larapex-charts.cdn') }}"></script> @endonce
@push('scripts') {!! $chart->script() !!} @endpush

SPA / Inertia / Livewire / API. Skip container()/script() entirely and serialise the options: $chart->toJson() (or toVue()), pass it as a prop, and instantiate new ApexCharts(el, options) yourself. This is the pattern to use whenever the front-end owns the lifecycle (Vue/React/Alpine) or the chart needs to be re-rendered on data refresh.

Polling / refresh. The package has no update API. Either build a fresh chart per refresh and re-mount client-side, or drop to plain ApexCharts updateSeries()/updateOptions() in your own JS, seeded from the chart's JSON.

Caching. Cache the data (Cache::remember('chart.revenue', ...) returning arrays) rather than the HTML. The container carries a generated id and the script embeds it; caching markup across requests leaks stale ids and stale data.

Testing. Assert on the serialised options rather than markup:

$options = json_decode($chart->toJson(), true);
$this->assertSame(['Jan', 'Feb'], $options['xaxis']['categories'] ?? $options['labels']);

Feature-test the controller for a 200 and a non-empty chart variable; snapshot the JSON only if you accept churn on upgrades.

Integration tips. Feed chart data from query objects/resources that already return int/float — cast at the database or resource layer. When a chart lives beside filters, make the chart class accept a DTO (date range, segment) so Livewire/controller code stays a one-liner: app(RevenueChart::class)->build($filters).

Gotchas and Tips

  • Output is raw HTML. container() and script() return HTML strings — {!! !!}, not {{ }}. Using escaped output shows markup as text and is the #1 "it doesn't work" report.
  • Script ordering. The ApexCharts library must be loaded before script() runs, and the container <div> must exist in the DOM. Push into a @stack('scripts') at the end of <body>; don't emit the script in <head>.
  • Livewire / Alpine morphing. Livewire DOM diffs can delete or duplicate the container, leaving a blank canvas. Wrap the component in wire:ignore and re-dispatch a browser event to rebuild the chart. The same applies to Turbo/Turbolinks navigation without data-turbo-permanent.
  • Duplicate ids. Each chart object generates an id; cloning a chart, calling container() twice, or rendering the same chart instance in two places (e.g. modal + page) collides. Use one instance per location.
  • Numeric types. PDO drivers often return numeric columns as strings; ApexCharts then treats values as categories or renders blank axis ticks. Cast to (int)/(float). JSON encoding of INF/NAN from bad divisions silently breaks the options object.
  • setXAxis() is labels, not axis config. It's a flat array of category labels. For datetime axes, log axes, min/max, tick formatting etc. you're beyond the wrapper's API — supply extra options yourself in the JSON path, or extend the chart class (see below).
  • Debugging. json_decode($chart->toJson(), true) printed or Log::info(...) it, then paste it into the ApexCharts docs demo. All rendering problems are options problems; the package itself is nearly stateless.
  • Extension point. The chart classes are ordinary PHP classes with an options array; subclass one and override the build/option assembly when you need options the fluent API doesn't expose. Prefer subclassing a chart class over patching vendor code — vendor patches vanish on composer update.
  • Config quirks. colors in config are defaults, and per-chart setColors() wins. Changing the CDN to a self-hosted path is the fix for offline/air-gapped deploys or strict CSP setups (you'll also need script-src allowances — ApexCharts uses inline styles).
  • v10.1.0 is tooling-only. Rector integration, PHPStan raised from level 1 → 8, CI wiring, and a release-please fix. No runtime, API, or config changes — upgrade is safe and needs no codemod. The real payoff is for teams running static analysis: the package's own types are now verified at level 8, and running Rector against your own app is a reasonable follow-up if you extend the chart classes.
  • Versioning. Major-line bumps (v9 → v10) have historically carried the option/API changes; treat those as the ones to read release notes for. Patch/minor within a major (like this one) has been additive or internal.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo