@adelamar/chartjs-plugin-crosshair

中文文档
2.0.3发布于 2023/08/17MITESM + CJS零依赖近 30 天下载 3647

Chart.js plugin to draw and sync vertical crosshair lines

原始使用文档
文档目录4 节
  1. Documentation
  2. Example
  3. Development
  4. License

Chart.js plugin to draw vertical crosshair, zoom, interpolate values and sync chart interactions.

Requires Chart.js 3.4.0 or later.

Documentation

Example

new Chart(ctx, {
  // ... data ...
  options: {
    // ... other options ...
    plugins: {
      tooltip: {
        mode: 'interpolate',
        intersect: false
      },
      crosshair: {
        line: {
          color: '#F66',  // crosshair line color
          width: 1        // crosshair line width
        },
        sync: {
          enabled: true,            // enable trace line syncing with other charts
          group: 1,                 // chart group
          suppressTooltips: false   // suppress tooltips when showing a synced tracer
        },
        zoom: {
          enabled: true,                                      // enable zooming
          zoomboxBackgroundColor: 'rgba(66,133,244,0.2)',     // background color of zoom box 
          zoomboxBorderColor: '#48F',                         // border color of zoom box
          zoomButtonText: 'Reset Zoom',                       // reset zoom button text
          zoomButtonClass: 'reset-zoom',                      // reset zoom button class
        },
        callbacks: {
          beforeZoom: () => function(start, end) {                  // called before zoom, return false to prevent zoom
            return true;
          },
          afterZoom: () => function(start, end) {                   // called after zoom
          }
        }
      }
    }
  }
});

Development

You first need to install node dependencies (requires Node.js):

> npm install

The following commands will then be available from the repository root:

> gulp build            // build dist files
> gulp build --watch    // build and watch for changes
> gulp lint             // perform code linting
> gulp docs             // generate GitBook documentation (`dist/docs`)
> gulp samples          // prepare samples for release (`dist/samples`)
> gulp package          // create an archive with dist files and samples
> gulp netlify          // prepare Netlify artifacts (`dist/www`)

License

chartjs-plugin-crosshair is available under the MIT license.

版本与发布记录

@adelamar/chartjs-plugin-crosshair 共发布 3 个版本,首次发布于 2023/08/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.3latest2023/08/173 年前
2.0.22023/08/173 年前
2.0.12023/08/173 年前

关于 @adelamar/chartjs-plugin-crosshair 的常见问题

@adelamar/chartjs-plugin-crosshair 是什么?

Chart.js plugin to draw and sync vertical crosshair lines

如何安装 @adelamar/chartjs-plugin-crosshair?

在项目目录运行 npm install @adelamar/chartjs-plugin-crosshair,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:chart.js(^4.0.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@adelamar/chartjs-plugin-crosshair 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/adelamar__chartjs-plugin-crosshair 是否存在。

@adelamar/chartjs-plugin-crosshair 支持 ESM 还是 CommonJS?

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

@adelamar/chartjs-plugin-crosshair 可以商用吗?

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

@adelamar/chartjs-plugin-crosshair 的下载量有多少?

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

@adelamar/chartjs-plugin-crosshair 还在维护吗?

最新版本 2.0.3 发布于 2023/08/17(3 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/08/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。