Skip to main content

Extending the System: Creating a Custom EChartBlock.vue Widget

This guide demonstrates how to add a new widget based on a different charting library (Apache ECharts) while adhering to our established data/params API. This is useful when you need chart types not available in ApexCharts, such as Sankey diagrams, graph visualizations, or advanced 3D plots. The process involves four key steps:
  1. Install the new libraries.
  2. Create the Vue component, translating our unified API to the ECharts format.
  3. Register the new component globally.
  4. Use the new component in your dashboard.

Step 1: Install ECharts Dependencies

First, add Apache ECharts and its official Vue 2 wrapper (vue-echarts) to your project.
(Note: For Vue 2, you typically need vue-echarts@5. NPM should resolve this correctly.)

Step 2: Create the EChartBlock.vue Component

This is the core of the integration. We will create a new Vue component that acts as an adapter, translating our generic params object into the specific, and often more complex, configuration object that ECharts requires. File: resources/js/components/EChartBlock.vue

Step 3: Register the New Component Globally

For the new component to be recognized, you must register it in your main JavaScript file alongside the others. File: resources/js/app.js
After adding this line, recompile your assets:

Step 4: Use the EChartBlock in Your Dashboard

You can now use <e-chart-block> just like any other widget. Let’s add it to our “Standard Live Dashboard” (MyReportPage.vue) to show how it fits in.
Update the Laravel Controller
First, add some data and params specifically for an ECharts pie chart in your controller. File: app/Http/Controllers/ReportController.php
Update the Vue Page Component
Now, simply add the <e-chart-block> tag to your layout. File: resources/js/components/MyReportPage.vue

Key Takeaways

  • The Power of the Unified API: Because we stuck to the data and params props, adding a completely new widget from a different library required zero changes to the DashboardLayout or the page’s data flow logic.
  • The Adapter Pattern: The new EChartBlock.vue component acts as an Adapter. It translates our simple, standardized API into the complex, specific API required by ECharts.
  • Infinite Extensibility: You can now follow this exact pattern to create <GoogleChartBlock>, <DataTableBlock>, <LeafletMapBlock>, or any other custom widget you can imagine. The core architecture remains clean and stable.