Skip to content

Donut Chart ​

Vue 已实现 · 还原验收 0/1 · 上游演示 · 固定版本源码

预览 ​

$115,150Monthly revenue

Select a plan to filter

用法 ​

vue
<script setup lang="ts">
import { shallowRef } from 'vue'
import { DonutChart } from 'beui-vue'

const selected = shallowRef<string | null>(null)
const segments = [
  { id: 'team', name: 'Team', color: '#2563eb', value: 42900 },
  { id: 'business', name: 'Business', color: '#38bdf8', value: 31250 },
  { id: 'enterprise', name: 'Enterprise', color: '#0d9488', value: 22600 },
  { id: 'starter', name: 'Starter', color: '#fbbf24', value: 18400 },
]
const usd = (value: number) => value.toLocaleString('en-US', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 })
</script>

<template>
  <div class="plans">
    <DonutChart label="Monthly revenue by plan" :labels="{ total: 'Monthly revenue' }" :segments="segments" :format-value="usd" :selected-id="selected" @select="selected = selected === $event ? null : $event" />
    <p aria-live="polite">{{ selected ? `Filtering by ${segments.find(segment => segment.id === selected)?.name}` : 'Select a plan to filter' }}</p>
  </div>
</template>

<style scoped>.plans { width: 100%; max-width: 36rem; margin-inline: auto; }.plans p { margin: 12px 4px 0; color: var(--beui-muted-foreground); font-size: 12px; }</style>

API ​

segments 定义各项占比,gap 与 thickness 调整环形。支持 v-model:active-id、selectedId、@select 和 #center 插槽。

还原验收 ​

基于 beUI 的独立 Vue 移植,依 MIT 许可证分发。