@automattic/charts

中文文档
4.15.1发布于 2026/11/06GPL-2.0-or-laterTypeScriptESM + CJS构建来源已验证近 30 天下载 5.2万

Display charts within Automattic products.

原始使用文档
文档目录10 节
  1. Requirements
  2. Quick Start
  3. Installation
  4. Importing Components
  5. Basic Usage Example
  6. Using this package in your WordPress plugin
  7. Contributing
  8. Local development with Storybook
  9. Security
  10. License

Automattic Charts

A comprehensive charting library for displaying interactive data visualizations within Automattic products. Built on top of modern libraries like @visx/xychart and designed for accessibility, responsiveness, and ease of use.

Explore the available charts and their documentation in Storybook.

Requirements

  • Node.js: >= 20.11.0
  • React: 18.x or 19.x

Quick Start

Installation

npm install @automattic/charts
# or
pnpm add @automattic/charts
# or
yarn add @automattic/charts

Importing Components

Import chart components from the main entry point:

import { LineChart, BarChart, PieChart } from '@automattic/charts';
import '@automattic/charts/style.css';

Modern bundlers tree-shake unused JavaScript automatically, so only the chart components you import are included in your bundle. Note that style.css includes styles for all charts.

Additional Entry Points

For utilities and auxiliary components, separate entry points are available:

  • @automattic/charts/hooks - React hooks
  • @automattic/charts/providers - Context providers
  • @automattic/charts/utils - Shared chart utility functions
  • @automattic/charts/visx/group - Visx group utilities
  • @automattic/charts/visx/legend - Visx legend utilities
  • @automattic/charts/visx/text - Visx text utilities

Available Style Imports

  • @automattic/charts/style.css - All chart styles

Basic Usage Example

import React from 'react';
import { LineChart } from '@automattic/charts';
import '@automattic/charts/style.css';

const data = [
    { date: new Date( '2024-01-01' ), value: 10 },
    { date: new Date( '2024-01-02' ), value: 90 }, // Sharp rise
    { date: new Date( '2024-01-03' ), value: 85 }, // Slight decline
    { date: new Date( '2024-01-04' ), value: 82 }, // Gradual decline
    { date: new Date( '2024-01-05' ), value: 5 }, // Sharp drop
    { date: new Date( '2024-01-06' ), value: 8 }, // Slight rise
    { date: new Date( '2024-01-07' ), value: 10 }, // Gradual rise
];

function MyComponent() {
    return <LineChart data={ data } width={ 400 } height={ 300 } />;
}

Using this package in your WordPress plugin

If you plan on using this package in your WordPress plugin, we would recommend that you use Jetpack Autoloader as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.

Contributing

Ready to contribute? Check out the Jetpack contributing guide and the Charts AI documentation guide for detailed information on adding new features and documentation.

Local development with Storybook

To run Storybook locally, from the root of the monorepo follow these steps:

  1. Run pnpm install to install the dependencies.
  2. Run cd projects/js-packages/charts to navigate to the charts package.
  3. Run pnpm run storybook to start the storybook server.

Security

Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.

License

Charts is licensed under GNU General Public License v2 (or later)

版本与发布记录

@automattic/charts 共发布 150 个版本,首次发布于 2024/12/20;过去 12 个月发布了 85 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
4.15.1latest2026/11/061 天前
4.15.02026/11/053 天前
4.14.02026/11/035 天前
4.13.02026/10/2910 天前
4.12.02026/10/2612 天前
4.11.12026/10/2118 天前

关于 @automattic/charts 的常见问题

@automattic/charts 是什么?

Display charts within Automattic products.

如何安装 @automattic/charts?

在项目目录运行 npm install @automattic/charts,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@automattic/charts 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@automattic/charts 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@automattic/charts 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.11.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@automattic/charts 可以商用吗?

@automattic/charts 使用 GPL-2.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以兼容的 GPL 许可开源。仅在内部使用、不对外分发时不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@automattic/charts 的下载量有多少?

根据 npm 官方下载统计,@automattic/charts 在 2026/10/07 – 2026/11/05 这 30 天内被下载 52,453 次,日均约 1,748 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@automattic/charts 还在维护吗?

最新版本 4.15.1 发布于 2026/11/06(1 天前);至今共发布 150 个版本,其中过去 12 个月发布了 85 个;首次发布于 2024/12/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。