# @coreui/react-chartjs 中文文档

规范地址：https://npmcn.com/package/%40coreui/react-chartjs/

版本：3\.0\.0
npm 元数据更新时间：2025-12-11T13:15:12.575Z
中文译文更新时间：2026-11-10T19:19:50.565Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40coreui/react-chartjs
原文对照：https://npmcn.com/package/%40coreui/react-chartjs/?lang=original
项目主页：https://coreui.io/react/docs/components/chart/
源码仓库：https://github.com/coreui/coreui-react

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1 MB，14 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- peer 依赖：react \>=17，react-dom \>=17
- 首次发布：2020-02-19T17:38:55.428Z
- 最新版本发布：2024-03-28T11:14:33.873Z
- 近 30 天下载量：317792（2026-10-11 至 2026-11-09，npm 官方下载统计）
- 已发布版本数：25（近 12 个月 0 个）

## 中文简介

Chart.js 的回放包装组件

## 安装

```sh
npm install @coreui/react-chartjs
```

也可以使用：`pnpm add @coreui/react-chartjs`、`yarn add @coreui/react-chartjs`、`bun add @coreui/react-chartjs`

## README

[![CoreUI logo](https://coreui.io/images/brand/coreui-signet.svg)](https://coreui.io/)

### CoreUI React.js 为图.js所包装

[**探索 @ coreui/ react- chartjs docs & example ”**](https://coreui.io/react/docs/components/chart/)  
  
[报告错误](https://github.com/coreui/coreui-react/issues/new?template=bug_report.md) • 妇女 [请求特性](https://github.com/coreui/coreui-react/issues/new?template=feature_request.md) • 妇女 [博客](https://blog.coreui.io/)

## 状态

[![npm package](https://img.shields.io/npm/v/@coreui/react-chartjs/latest?style=flat-square)](https://www.npmjs.com/package/@coreui/react-chartjs) [![NPM downloads](https://img.shields.io/npm/dm/@coreui/react-chartjs.svg?style=flat-square)](https://www.npmjs.com/package/@coreui/react-chartjs)

##### 安装 :

```bash
npm install @coreui/react-chartjs

# or

yarn add @coreui/react-chartjs
```

##### 导入 :

```jsx
import { CChart } from '@coreui/react-chartjs'
```

或者说

```js
import {
  CChart,
  CChartBar,
  CChartHorizontalBar,
  CChartLine,
  CChartDoughnut,
  CChartRadar,
  CChartPie,
  CChartPolarArea,
} from '@coreui/react-chartjs'
```

##### 道具 :

```js

/**
* A string of all className you want applied to the base component.
 */
className?: string
/**
 * Enables custom html based tooltips instead of standard tooltips.
 *
 * @default true
 */
customTooltips?: boolean
/**
 * The data object that is passed into the Chart.js chart (more info).
 */
data: ChartData | ((canvas: HTMLCanvasElement) => ChartData)
/**
 * A fallback for when the canvas cannot be rendered. Can be used for accessible chart descriptions.
 *
 * {@link https://www.chartjs.org/docs/latest/general/accessibility.html More Info}
 */
fallbackContent?: React.ReactNode
/**
 * Proxy for Chart.js getDatasetAtEvent. Calls with dataset and triggering event.
 */
getDatasetAtEvent?: (
  dataset: InteractionItem[],
  event: React.MouseEvent<HTMLCanvasElement>,
) => void
/**
 * Proxy for Chart.js getElementAtEvent. Calls with single element array and triggering event.
 */
getElementAtEvent?: (
  element: InteractionItem[],
  event: React.MouseEvent<HTMLCanvasElement>,
) => void
/**
 * Proxy for Chart.js getElementsAtEvent. Calls with element array and triggering event.
 */
getElementsAtEvent?: (
  elements: InteractionItem[],
  event: React.MouseEvent<HTMLCanvasElement>,
) => void
/**
 * Height attribute applied to the rendered canvas.
 *
 * @default 150
 */
height?: number
/**
 * ID attribute applied to the rendered canvas.
 */
id?: string
/**
 * The options object that is passed into the Chart.js chart.
 *
 * {@link https://www.chartjs.org/docs/latest/general/options.html More Info}
 */
options?: ChartOptions
/**
 * The plugins array that is passed into the Chart.js chart (more info)
 *
 * {@link https://www.chartjs.org/docs/latest/developers/plugins.html More Info}
 */
plugins?: Plugin[]
/**
 * If true, will tear down and redraw chart on all updates.
 *
 * @default false
 */
redraw?: boolean
/**
 * Chart.js chart type.
 *
 * @type {'line' | 'bar' | 'radar' | 'doughnut' | 'polarArea' | 'bubble' | 'pie' | 'scatter'}
 */
type: ChartType
/**
 * Width attribute applied to the rendered canvas.
 *
 * @default 300
 */
width?: number
/**
 * Put the chart into the wrapper div element.
 *
 * @default true
 */
wrapper?: boolean
```

##### 用途 :

```jsx
...
class CoreUICharts extends Component {
...
render() {
  return (
    <CChart
      type='line'
      data={{
        labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
        datasets: [
          {
            label: '2019',
            backgroundColor: 'rgba(179,181,198,0.2)',
            borderColor: 'rgba(179,181,198,1)',
            pointBackgroundColor: 'rgba(179,181,198,1)',
            pointBorderColor: '#fff',
            pointHoverBackgroundColor: '#fff',
            pointHoverBorderColor: 'rgba(179,181,198,1)',
            tooltipLabelColor: 'rgba(179,181,198,1)',
            data: [65, 59, 90, 81, 56, 55, 40]
          },
          {
            label: '2020',
            backgroundColor: 'rgba(255,99,132,0.2)',
            borderColor: 'rgba(255,99,132,1)',
            pointBackgroundColor: 'rgba(255,99,132,1)',
            pointBorderColor: '#fff',
            pointHoverBackgroundColor: '#fff',
            pointHoverBorderColor: 'rgba(255,99,132,1)',
            tooltipLabelColor: 'rgba(255,99,132,1)',
            data: [28, 48, 40, 19, 96, 27, 100]
          }
        ],
      }}  
      options={{
        aspectRatio: 1.5,
        tooltips: {
          enabled: true
        }
      }}
    />
  )
}
...
```

## 常见问题

### @coreui/react-chartjs 是什么？

Chart\.js 的回放包装组件

### 如何安装 @coreui/react-chartjs？

在项目目录运行 npm install @coreui/react-chartjs，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：react（\>=17）、react-dom（\>=17）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @coreui/react-chartjs 支持 TypeScript 吗？

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

### @coreui/react-chartjs 支持 ESM 还是 CommonJS？

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

### @coreui/react-chartjs 可以商用吗？

@coreui/react-chartjs 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @coreui/react-chartjs 的下载量有多少？

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

### @coreui/react-chartjs 还在维护吗？

最新版本 3\.0\.0 发布于 2024/03/28（2 年前）；至今共发布 25 个版本，其中过去 12 个月发布了 0 个；首次发布于 2020/02/20。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

