apexcharts.js README

The project's README from github.com/apexcharts/apexcharts.js. As one markdown file: README.md.

ApexCharts

Modern, interactive JavaScript charts your users will love, built for dashboards, SaaS, and data-heavy UIs.

npm version downloads TypeScript License jsdelivr

Live demos · Documentation · License

ApexCharts gallery

Why ApexCharts

New in v6

Version 6 turns a chart from a picture you look at into a surface you investigate, author, and share. Most features below are opt-in and tree-shakeable; existing configs keep working unchanged.

Install

npm install apexcharts

Or via CDN:

<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>

Quick start

import ApexCharts from 'apexcharts'

const chart = new ApexCharts(document.querySelector('#chart'), {
  chart: { type: 'bar' },
  series: [{ name: 'Sales', data: [30, 40, 35, 50, 49, 60, 70, 91, 125] }],
  xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999] }
})

chart.render()

Browse 100+ ready-to-use samples: copy, paste, ship.

Chart types

Combine any of the above as mixed/combo charts, stacked variants, sparklines, or synchronized multi-chart layouts.

Framework wrappers

Official:

Community:

Server-side rendering

Render chart HTML on the server, then hydrate in the browser. Works with Next.js, Nuxt, SvelteKit, Astro, Remix, and any Node-based framework.

// Server
import ApexCharts from 'apexcharts/ssr'

const chartHTML = await ApexCharts.renderToHTML({
  chart: { type: 'bar' },
  series: [{ data: [30, 40, 35, 50, 49, 60, 70, 91, 125] }],
  xaxis: { categories: [1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999] }
}, { width: 500, height: 300 })

// Returns hydration-ready HTML with embedded SVG
// Client
import ApexCharts from 'apexcharts/client'

ApexCharts.hydrate(document.getElementById('my-chart'))
// or: ApexCharts.hydrateAll()

No more dynamic(() => import(...), { ssr: false }) workarounds: the chart renders on the server and becomes interactive on hydration.

Tree-shaking: ship only what you use

import ApexCharts from 'apexcharts' gives you every chart type and the everyday features. Nine optional features ship outside it and are imported explicitly (marked opt-in below); each warns in the console if its config is set but the feature is absent. Adding one to the default bundle is a single line, and the two share one copy of the core:

import ApexCharts from 'apexcharts'
import 'apexcharts/features/trellis'

For a smaller bundle still, start from apexcharts/core and add only what you need:

import ApexCharts from 'apexcharts/core'   // bare class: no chart types, no features

// Chart types (match the value of chart.type)
import 'apexcharts/line'
import 'apexcharts/bar'
// import 'apexcharts/area'
// import 'apexcharts/scatter'
// import 'apexcharts/unit'         // dot / pictogram / waffle / beeswarm (premium; 'waffle' aliases this)

// Optional features
import 'apexcharts/features/legend'
import 'apexcharts/features/toolbar'      // zoom/pan toolbar
// import 'apexcharts/features/exports'      // SVG/PNG/CSV download
// import 'apexcharts/features/annotations'
// import 'apexcharts/features/keyboard'     // keyboard navigation
// import 'apexcharts/features/drilldown'    // hierarchical drill-down
// import 'apexcharts/features/morph'        // animated chart-type morphs
// import 'apexcharts/features/history'      // undo/redo (premium, opt-in)
// import 'apexcharts/features/perspectives' // shareable view state (premium, opt-in)
// import 'apexcharts/features/storyboard'   // scrollytelling, incl. perspectives (premium, opt-in)
// import 'apexcharts/features/facet'        // design tokens + OS themes
// import 'apexcharts/features/weave'        // plugin platform
// import 'apexcharts/features/marks'        // custom series types
// import 'apexcharts/features/link'         // crossfilter / linked views (premium, opt-in)
// import 'apexcharts/features/ink'          // on-chart annotation editing (premium, opt-in)
// import 'apexcharts/features/measure'      // measure/delta ruler (premium, opt-in)
// import 'apexcharts/features/context-menu' // right-click context menu (premium, opt-in)
// import 'apexcharts/features/renderer-canvas' // canvas series renderer (opt-in)
// import 'apexcharts/features/trellis'     // small multiples (premium, opt-in)
// import 'apexcharts/features/raincloud'   // raincloud chart type statistics (premium, opt-in)

A page without a bundler gets the same choice. apexcharts.js stays batteries-included, and apexcharts.core.min.js is the lean baseline you build up from:

<script src="https://cdn.jsdelivr.net/npm/apexcharts/dist/apexcharts.core.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/apexcharts/dist/line.js"></script>
<script src="https://cdn.jsdelivr.net/npm/apexcharts/dist/features/legend.js"></script>

Opt-in features work the same way there: load dist/features/<name>.js after whichever bundle the page already has.

See the tree-shaking guide for the complete list of entry points.

Shapes for the unit chart

apexcharts/unit-shapes is a companion kit: 39 shapes a unit chart can pack its dots into, as silhouettes (heart, house, globe, tree), stroked glyphs (checkmark, arrow, heartbeat trace) and a composer that draws a number in its own dots. Every shape is a plain function of the marks and the plot rectangle, so it repacks at any dot count and any size, and importing one costs about 4 KB gzipped with the rest shaken out.

import ApexCharts from 'apexcharts'
import { heart } from 'apexcharts/unit-shapes'

new ApexCharts(el, {
  chart: { type: 'unit' },
  series: [576, 168, 42, 34],
  labels: ['Owned', 'Mortgaged', 'Renting', 'Other'],
  plotOptions: { unit: { layout: 'custom', positions: heart } },
}).render()

Shapes are composable (outlined(heart) traces it instead of filling it, heart.with({ order: 'cols' }) changes where each series band lands), and preview(heart, { series }) renders one to an SVG string with no chart and no DOM, for docs and build-time images. From a script tag, dist/unit-shapes.js exposes the same kit as ApexUnitShapes and registers every shape by name.

The shape you want is probably not one of the 39, and it does not have to be. positions takes any function of the marks and the plot rectangle, so there are three ways in, none of which needs a release from us:

import { shapeFrom, strokeFrom } from 'apexcharts/unit-shapes'

shapeFrom('M 26 71 A 24 21 0 1 1 74 71 …')        // your own outline, packed like ours
strokeFrom('M 6 76 L 24 44 L 40 60 …', { width: 12 })  // a centreline, for a line
positions: (objects, rect) => objects.map(…)      // your own rule, no kit at all

Working demo of all three, including the outline-authoring rules (subpaths union, a reverse-wound one cuts a hole): bring-your-own-shape.

Premium features & licensing

Most of ApexCharts is free and open source. A small set of advanced features are premium and require a license key:

Feature Enabled by
Unit chart type (dot / pictogram / waffle / beeswarm) chart.type: 'unit' / chart.type: 'waffle'
Raincloud chart type (half-density + box + raw points) chart.type: 'raincloud' (needs apexcharts/features/raincloud, not in the default bundle)
Storyboard (scrollytelling) chart.storyboard.bind(...)
Linked views / crossfilter chart.link.enabled / chart.link.dimension / ApexCharts.crossfilter()
Ink layer (on-chart annotation editing) chart.ink.enabled
Measure / delta ruler chart.measure.enabled
Context menu (right-click) chart.contextMenu.enabled
Perspectives (shareable view state) chart.perspectives.apply() / .save() / ApexCharts.perspectives.decode()
History (undo/redo) chart.history.enabled

Without a valid key these features still work (trial mode), but the chart shows an "APEXCHARTS" watermark. A valid key removes it. Every other chart type and feature is free and never watermarked; the premium chart types are unit (aliased by waffle) and raincloud, both listed above.

import ApexCharts from 'apexcharts'

// Set once, before rendering. Applies to every chart on the page.
ApexCharts.setLicense('APEX-xxxxxxxx')

Alternatives to setLicense:

// Global variable (used when setLicense was not called):
window.Apex = { license: 'APEX-xxxxxxxx' }

// Per-chart override (most specific wins):
new ApexCharts(el, { chart: { license: 'APEX-xxxxxxxx' /* ... */ } })

Precedence per chart: chart.license -> ApexCharts.setLicense() -> window.Apex.license -> unlicensed (trial). The watermark is re-evaluated on every render, so a late setLicense(validKey) followed by chart.update() clears it.

Keys are shared across the whole ApexCharts family (apexgantt, apextree, apexsankey, apex-grid-enterprise, apexstock), so one customer key works everywhere. Get a license at apexcharts.com/pricing.

Browser support

ApexCharts works in all modern evergreen browsers (Chrome, Firefox, Safari, Edge). For server-side rendering, Node.js 18+ is required.

Documentation

Contributing

npm install
npm run dev     # vite build --watch
npm test        # e2e + unit

See CONTRIBUTING.md for setup, coding conventions, and PR guidelines.

License

ApexCharts uses a revenue-based license:

Full terms: apexcharts.com/license

Need an enterprise data grid?

We've partnered with Infragistics, creators of Ignite UI: high-performance data grids that handle unlimited rows and columns, with custom templates and real-time updates.

Ignite UI Data Grid

Available for:

Angular · React · Blazor · Web Components · jQuery

Contact

apexcharts.js (apexcharts/apexcharts.js)

Searching Database…

这是什么?ApexCharts 是一个 JavaScript 图表库,用于构建基于 SVG、可交互的图表,适用于仪表盘、SaaS 产品和数据密集型界面。
这是独立应用,还是可以加到我自己项目里的库?它是一个库,可以通过 npm 或 CDN 安装,并在你自己的 JS/TS 代码中调用;它在运行时零依赖,可以配合原生 JS 或任何框架使用。
怎么把它加到项目里?用 npm 安装包或通过 CDN 加载,然后引入 ApexCharts,根据配置对象创建图表;还提供了 100 多个可直接复制使用的现成示例。
用它必须先装 React、Vue 或其他框架吗?不需要,它在运行时零依赖,可以独立使用;如果需要,也有针对 React、Vue 3/2、Angular、Blazor 和 Stencil 的官方封装。
付费功能(比如 unit/waffle 图表)不付费能用吗?高级图表类型和功能(unit/waffle、raincloud、storyboard、crossfilter、墨迹标注、测量尺、右键菜单、perspectives、历史记录)无需许可证密钥即可使用,但在添加有效密钥之前会显示“APEXCHARTS”水印。
这是给谁用的?面向需要构建仪表盘、SaaS 产品或任何需要交互式图表应用的前端开发者,从简单的折线图、柱状图,到实时流式数据图,再到包含数十万个数据点的高密度散点图都适用。
授权条款是什么?ApexCharts 采用基于营收的授权:年度总营收低于 200 万美元的个人和组织可免费使用(包括商业和内部使用);超过该门槛则需要购买商业授权。
开箱即用支持哪些图表类型?支持 18 种以上图表类型,包括折线图、面积图、柱状图、条形图、饼图、环形图、雷达图、热力图、树状图、K 线图、箱线图、小提琴图、漏斗图、金字塔图和仪表盘图,还包括混合/组合图表和迷你图等变体。
支持服务端渲染吗?支持,它可以在服务端为 Next.js、Nuxt、SvelteKit、Astro 等基于 Node 的框架渲染真实的 SVG,然后在客户端完成激活(hydration),无需动态导入(dynamic import)之类的 SSR 变通方案。
能控制打包体积吗?可以,它支持 Tree Shaking,只引入你需要的图表类型和功能,通常可将打包体积减少 30%-60%;使用精简的 apexcharts/core 版本,还可以只添加你实际用到的部分。
6 版有什么新功能?6 版新增了插件平台、针对高密度数据系列的 Canvas 渲染、撤销/重做历史、可分享的视图状态“视角(perspectives)”、自适应操作系统的主题、自定义系列类型、原生触控手势、交叉过滤仪表盘、标注编辑、测量尺、右键菜单、实时流式数据,以及滚动叙事(storyboard)。
What are similar projects?uPlot, dsh-genui, visx, G2, highcharts, charts, ascii, vega
Creator
apexcharts
Size
234 MB
Stars
15.2K
Age
8y
Commits · 90 Days