ApexCharts
raw JSON →ApexCharts is a modern, open-source JavaScript charting library for building interactive data visualizations. It provides a wide array of over a dozen chart types, offering responsive and feature-rich charts suitable for applications and dashboards. The current stable version is 5.10.6, with frequent patch releases addressing bugs and introducing minor features, sometimes on a weekly or bi-weekly cadence. Key differentiators include its extensive chart catalogue, built-in server-side rendering (SSR) support, modular entry points for efficient tree-shaking, and accessibility features like color-blind modes. It also offers official wrappers for popular frameworks like React, Vue, and Angular, simplifying integration into various web environments.
Common errors
error Error: Chart type not registered (or similar runtime error indicating missing chart type) ↓
sideEffects are properly configured in package.json for apexcharts (check v5.10.2 release notes for patterns). If using modular imports, make sure import 'apexcharts/<chart-type>' statements are not inadvertently tree-shaken. For bundler issues with duplicate modules (e.g., CJS/ESM mix), try to unify module systems or configure optimizeDeps if using Vite. error ReferenceError: SVG is not a function ↓
ApexCharts from apexcharts/ssr for all server-side rendering logic. If the issue persists, check your SSR framework's documentation for mocking browser globals. error Legend stays greyed out after re-enabling hidden series (visual bug) ↓
Warnings
breaking Older bundler configurations or mixed CJS/ESM imports can lead to silent tree-shaking issues, where chart types or features are unexpectedly omitted from production builds, resulting in runtime errors or missing functionality. This was particularly prevalent before v5.10.2. ↓
gotcha When using ApexCharts in a Server-Side Rendering (SSR) environment (e.g., Next.js, Nuxt), the correct SSR-specific import path (`apexcharts/ssr`) must be used. Using the standard client-side import can lead to errors like 'SVG is not a function' or other Node.js environment-specific crashes. ↓
gotcha Since v5.7.0, ApexCharts introduced feature-level tree-shaking and in v5.10.0, per-type modular entry points. Importing the entire library (`import ApexCharts from 'apexcharts'`) will include all chart types and features, negating the bundle size benefits of modular imports. ↓
deprecated Locale file names were renamed to their correct ISO codes in v5.10.4. Older, incorrect filenames might still function but are considered deprecated and could be removed in future major versions. ↓
Install
npm install apexcharts yarn add apexcharts pnpm add apexcharts Imports
- ApexCharts wrong
const ApexCharts = require('apexcharts')correctimport ApexCharts from 'apexcharts' - ApexCharts wrong
import ApexCharts from 'apexcharts'correctimport ApexCharts from 'apexcharts/ssr' - ApexCharts (modular core) wrong
import ApexCharts from 'apexcharts'correctimport ApexCharts from 'apexcharts/core'; import 'apexcharts/line'; - ChartOptions (TypeScript type) wrong
import { ApexOptions } from 'apexcharts'correctimport type { ApexOptions } from 'apexcharts'
Quickstart
import ApexCharts from 'apexcharts';
const chartElement = document.querySelector('#chart');
const options = {
chart: {
type: 'bar',
height: 350
},
series: [
{
name: 'sales',
data: [30, 40, 35, 50, 49, 60, 70, 91, 125]
}
],
xaxis: {
categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999]
},
title: {
text: 'Basic Bar Chart Example',
align: 'left'
}
};
if (chartElement) {
const chart = new ApexCharts(chartElement, options);
chart.render();
} else {
console.error('Chart element with id "#chart" not found.');
}
// Example of updating series data (requires a chart instance already rendered)
// setTimeout(() => {
// chart.updateSeries([{ data: [20, 50, 45, 30, 70, 55, 80, 100, 110] }]);
// }, 5000);