- How do I install mitoteam/jpgraph in a Laravel application?
- Install it with composer require mitoteam/jpgraph. No Laravel service provider is required because the package is a Composer wrapper around the original JpGraph library. Load the library where needed with MtJpGraph::load() and then use the original JpGraph classes as usual.
- Which Laravel and PHP versions does mitoteam/jpgraph support?
- The package supports PHP 5.5 through PHP 8.5, so it works with Laravel versions that run on those PHP releases. Modern Laravel applications typically use PHP 8.1 or newer and can use the wrapper without special configuration. Always confirm your application's Composer PHP constraint matches the version you install.
- How do I load JpGraph chart modules in Laravel?
- Call MtJpGraph::load() with a single module name like 'bar', or pass an array such as ['bar', 'line'] for multiple modules. The loader checks internally whether the library or module is already loaded, so repeated calls are safe. Loading only the modules you need helps reduce memory usage.
- What is Extended Mode in mitoteam/jpgraph and when should I use it?
- Extended Mode is enabled by passing true as the second argument to MtJpGraph::load(), for example MtJpGraph::load(['bar', 'line'], true). It applies fixes for known bugs in the original JpGraph library and is recommended for production use. You can combine Extended Mode with any module loading combination.
- How do I generate and return a chart image from a Laravel controller?
- Load the required modules, create a JpGraph Graph instance, configure the chart, and call stroke() to render the image. Return a Laravel response with the image data and a Content-Type header such as image/png. For downloads, use response()->streamDownload(), and for Blade views you can embed the image via a data URL or an API endpoint.
- How do I change the JpGraph font directory or cache settings in Laravel?
- Define or override JpGraph constants such as TTF_DIR and CACHE_FILE_GROUP before calling MtJpGraph::load(). In Laravel you can do this in AppServiceProvider or a dedicated service using config or environment values. Make sure any cache or font paths are writable by the application.
- Does JpGraph work with Laravel tests and PHPUnit?
- The original JpGraph library installs a global exception handler, which can interfere with Laravel's error handling and PHPUnit. The wrapper provides MtJpGraph::setSkipExceptionHandler(true), which you should enable in test environments. HTTP tests can assert image responses, while unit tests may mock or isolate chart generation.
- Can I generate charts asynchronously with Laravel queues?
- Yes. Create a queued job that loads the required JpGraph modules, builds the chart, and writes the rendered image to storage. This avoids slowing down API responses or real-time dashboards. The generated file can then be served from storage, attached to emails, or included in scheduled reports.
- Is mitoteam/jpgraph actively maintained and safe for production?
- The mitoteam/jpgraph wrapper is actively patched, but the original JpGraph library is legacy code last updated in 2022. Extended Mode addresses several known bugs, improving reliability for production charts. Pin the package version, monitor PHP deprecation logs, and evaluate alternatives for highly interactive or long-term charting needs.
- What are alternatives to JpGraph for server-side charts in Laravel?
- Alternatives include client-side libraries like Chart.js, image-generation APIs such as QuickChart, and PHP charting libraries like pChart or SVG-based renderers. JpGraph remains useful for legacy-style server-rendered PNG or JPEG charts without JavaScript. Choose based on interactivity requirements, maintenance status, and whether charts must be generated inside PHP.