npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@oiij/e-charts

v0.0.18

Published

A Vue Composable for ECharts

Readme

@oiij/e-charts

NPM version MIT-license

简介

Use ECharts 是基于 Apache ECharts 的 Vue 3 组合式函数封装,提供便捷的图表渲染功能,帮助开发者快速构建数据可视化应用。

特点

📊 图表丰富

  • 📈 内置柱状图、折线图、饼图
  • 🔌 支持扩展注册更多图表类型
  • ⚙️ 提供丰富的配置选项

🔄 响应式设计

  • 📐 自动响应容器尺寸变化
  • ⏱️ 支持防抖 resize
  • 📱 自适应屏幕尺寸

🌙 暗黑模式

  • 🌓 支持暗黑模式切换
  • 🔄 自动重建图表应用主题

🔒 类型安全

  • 📝 完整的 TypeScript 类型定义
  • 💡 提供准确的类型推断和代码提示
  • ⚡ 支持 Vue 3 的 Composition API 类型系统

安装

# 使用 pnpm
pnpm add @oiij/e-charts

# 使用 npm
npm install @oiij/e-charts

# 使用 yarn
yarn add @oiij/e-charts

依赖

  • vue: ^3.0.0
  • @vueuse/core: ^10.0.0
  • echarts: ^5.0.0

示例

基础使用

<script setup>
import { useECharts } from '@oiij/e-charts'
import { useTemplateRef } from 'vue'

const { chartOption } = useECharts(useTemplateRef('chart'), {
  chartOption: {
    title: { text: '销售数据' },
    xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] },
    yAxis: { type: 'value' },
    series: [{ type: 'bar', data: [120, 200, 150, 80, 70] }]
  }
})
</script>

<template>
  <div ref="chart" style="width: 100%; height: 400px;" />
</template>

响应式配置

<script setup>
import { useECharts } from '@oiij/e-charts'
import { computed, ref, useTemplateRef } from 'vue'

const salesData = ref([120, 200, 150, 80, 70])

const chartOption = computed(() => ({
  title: { text: '销售数据' },
  xAxis: { type: 'category', data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] },
  yAxis: { type: 'value' },
  series: [{ type: 'bar', data: salesData.value }]
}))

const { onRendered, onUpdate } = useECharts(useTemplateRef('chart'), {
  chartOption
})

onRendered((instance) => {
  console.log('图表渲染完成', instance)
})

onUpdate((option) => {
  console.log('配置更新', option)
})
</script>

<template>
  <div ref="chart" style="width: 100%; height: 400px;" />
</template>

暗黑模式

<script setup>
import { useECharts } from '@oiij/e-charts'
import { ref, useTemplateRef } from 'vue'

const darkMode = ref(false)

const { setDarkMode } = useECharts(useTemplateRef('chart'), {
  chartOption: { /* ... */ },
  darkMode
})
</script>

<template>
  <button @click="darkMode = !darkMode">
    切换主题
  </button>
  <div ref="chart" style="width: 100%; height: 400px;" />
</template>

注册扩展图表

import { register } from '@oiij/e-charts'
import { RadarChart, ScatterChart } from 'echarts/charts'

// 注册额外的图表类型
register([RadarChart, ScatterChart])

API

useECharts(templateRef, options?)

使用 ECharts 创建图表。

参数

| 参数 | 类型 | 说明 | | ------------- | -------------------------- | ------------------ | | templateRef | TemplateRef<HTMLElement> | 图表容器的模板引用 | | options | UseEChartsOptions | 图表配置选项 |

UseEChartsOptions

| 选项 | 类型 | 默认值 | 说明 | | ------------- | --------------------------------- | ------- | ------------------ | | chartOption | MaybeRefOrGetter<EChartsOption> | - | ECharts 配置 | | darkMode | MaybeRefOrGetter<boolean> | false | 是否开启暗黑模式 | | initOptions | EChartsInitOpts | - | ECharts 初始化选项 |

返回值

| 属性 | 类型 | 说明 | | ------------------------ | ----------------------------- | ---------------- | | templateRef | TemplateRef<HTMLElement> | 图表容器引用 | | eChartInst | ShallowRef<ECharts \| null> | ECharts 实例 | | chartOption | Ref<EChartsOption> | 图表配置 | | darkMode | Ref<boolean> | 暗黑模式状态 | | setOption(option?) | Function | 设置图表配置 | | setDarkMode(darkMode?) | Function | 设置暗黑模式 | | onRendered(callback) | Function | 图表渲染完成事件 | | onUpdate(callback) | Function | 配置更新事件 | | onResize(callback) | Function | 容器尺寸变化事件 | | onDispose(callback) | Function | 图表销毁事件 |

register(ext)

注册 ECharts 扩展组件。

参数

| 参数 | 类型 | 说明 | | ----- | --------------------------- | ------------ | | ext | Parameters<typeof use>[0] | 扩展组件数组 |

内置图表类型

  • BarChart - 柱状图
  • LineChart - 折线图
  • PieChart - 饼图

类型定义

import type { ECharts, EChartsInitOpts } from 'echarts/core'
import type { MaybeRefOrGetter, TemplateRef } from 'vue'

export type EChartsOption = ComposeOption<
  | BarSeriesOption
  | LineSeriesOption
  | PieSeriesOption
  | TitleComponentOption
  | LegendComponentOption
  | TooltipComponentOption
  | GridComponentOption
  | ToolboxComponentOption
  | DatasetComponentOption
>

export type UseEChartsOptions = {
  chartOption?: MaybeRefOrGetter<EChartsOption>
  darkMode?: MaybeRefOrGetter<boolean>
  initOptions?: EChartsInitOpts
}

export type UseEChartsReturns = {
  templateRef: TemplateRef<HTMLElement>
  eChartInst: ShallowRef<ECharts | null>
  chartOption: Ref<EChartsOption | undefined>
  darkMode: Ref<boolean | undefined>
  setOption: (option?: EChartsOption) => void
  setDarkMode: (darkMode?: boolean) => void
  onRendered: (callback: (instance: ECharts) => void) => void
  onUpdate: (callback: (option: EChartsOption) => void) => void
  onResize: (callback: (size: { width: number, height: number }) => void) => void
  onDispose: (callback: () => void) => void
}

export declare function useECharts(templateRef: TemplateRef<HTMLElement>, options?: UseEChartsOptions): UseEChartsReturns
export declare function register(ext: Parameters<typeof use>[0]): void

在线文档

在线文档