- How do I install LiveCharts in a Laravel 13 project with Livewire 4?
- Run `composer require matheusmarnt/livecharts` followed by `php artisan livecharts:install`. This publishes config, assets, and stubs. Ensure your Laravel version is 10–13 and Livewire is 3–4. The installer handles asset registration automatically for local or CDN modes.
- Can I use LiveCharts with Laravel Vite for optimized asset delivery?
- Yes, LiveCharts supports Vite out of the box. Configure `LIVECHARTS_ASSETS_MODE=both` in your `.env` to use both local and CDN assets. The package includes Vite-compatible directives for seamless integration with Laravel’s modern asset pipeline.
- What chart types are available, and how do I customize them?
- LiveCharts offers 18 chart types, including line, bar, pie, treemap, and candlestick charts. Customize them via the fluent API (e.g., `LiveCharts::line()->labels()->dataset()->colors()`) or by extending the `Chart` class. Engine-specific features like ApexCharts’ `strokeDashArray` can be exposed via the `withEngineConfig()` method.
- How does LiveCharts handle real-time updates with Livewire?
- LiveCharts leverages Livewire’s reactivity model. When chart data changes (e.g., via `wire:model` or `wire:poll`), the component re-renders automatically. For advanced use cases, integrate with Laravel Echo for broadcasting updates via WebSocket channels, ensuring low-latency reactivity.
- Is LiveCharts compatible with multi-tenancy or SaaS applications?
- Yes, but broadcasting requires careful channel management. Use `broadcastOn()` with tenant-specific channels (e.g., `private-tenant.{id}.chart-updates`) to isolate updates. Ensure your WebSocket provider (Pusher, Ably) scales with your tenant count to avoid race conditions or throttling.
- What’s the best way to handle large datasets (e.g., 10K+ data points) without performance issues?
- For large datasets, enable pagination or lazy-loading in your data source. LiveCharts supports virtual scrolling for charts like treemap or matrix via engine-specific optimizations (e.g., ApexCharts’ `chartOptions['plugins']['scrollbar']`). Test with `wire:lazy` or `wire:poll` to minimize hydration cycles.
- How do I add a custom chart engine like Highcharts or ECharts?
- Implement the `EngineAdapter` contract and register it via `LiveCharts::registerEngine()`. The adapter must handle engine-specific configurations, plugins, and asset loading. Example: `LiveCharts::registerEngine(new HighchartsAdapter());`. Check the package’s `src/Engines` directory for reference implementations.
- What’s the recommended CI/CD strategy for asset publishing?
- Automate asset publishing in your deployment pipeline. For GitHub Actions, add a step to run `php artisan livecharts:publish --tag=assets` before `npm run build`. For Docker, ensure `public/vendor/livecharts/js/` is copied during build. Use `LIVECHARTS_ASSETS_MODE=cdn` in production to avoid silent failures from missing assets.
- How does LiveCharts handle errors, like missing data or invalid configurations?
- LiveCharts validates chart configurations during hydration and throws exceptions for invalid data or engine errors. Use `@error` directives in Blade to display user-friendly messages. For graceful fallbacks, implement a `ChartFallback` trait or override the `render()` method to return a static placeholder (e.g., a loading spinner).
- Are there alternatives to LiveCharts for Laravel Livewire charts?
- Alternatives include `beyondcode/laravel-apexcharts` (ApexCharts-focused) or `chartjs/chart.js` with manual Livewire integration. LiveCharts stands out by offering a unified PHP API for multiple engines, reducing boilerplate, and integrating natively with Livewire’s reactivity. For JavaScript-heavy projects, consider `laravel-chartjs` but expect more frontend complexity.