Skip to content

Funnel Chart ​

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

预览 ​

From first visit to first payment

Product conversion · Sample cohorts

Visitors 100.0%Signed up 65.0%Activated 45.0%Started trial 30.0%Subscribed 18.0%
24,000 → 4,320 peopleOverall conversion 18.0%
Inspect a stage to see conversion and drop-off

用法 ​

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

const direction = shallowRef<'vertical' | 'horizontal'>('vertical')
const labels = ['Visitors', 'Signed up', 'Activated', 'Started trial', 'Subscribed']
const cohorts = [[24000, 15600, 10800, 7200, 4320], [28000, 18200, 13650, 9100, 6370], [22000, 13200, 7920, 4752, 2376]]
const cohort = shallowRef(0)
const stages = computed(() => labels.map((label, index) => ({ id: label, label, value: cohorts[cohort.value][index] })))
</script>

<template>
  <div class="chart-demo"><header><div><strong>From first visit to first payment</strong><p>Product conversion · Sample cohorts</p></div><button type="button" @click="cohort = (cohort + 1) % cohorts.length">Next cohort</button></header>
    <fieldset aria-label="Funnel direction"><button type="button" :aria-pressed="direction === 'vertical'" @click="direction = 'vertical'">Vertical</button><button type="button" :aria-pressed="direction === 'horizontal'" @click="direction = 'horizontal'">Horizontal</button></fieldset>
    <FunnelChart :stages="stages" :direction="direction" />
    <footer>Inspect a stage to see conversion and drop-off</footer>
  </div>
</template>
<style scoped>
.chart-demo { width: 100%; min-width: 0; margin-inline: auto; }
.chart-demo > header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 20px; }
.chart-demo header strong { font-size: 14px; font-weight: 500; }
.chart-demo header p, .chart-demo > p { margin: 4px 0 0; color: var(--beui-muted-foreground); font-size: 12px; line-height: 16px; }
.chart-demo header button,.chart-demo fieldset button { padding: 6px 12px; background: transparent; border: 0; border-radius: 8px; font: inherit; font-size: 13px; cursor: pointer; }
.chart-demo header button:hover,.chart-demo fieldset button[aria-pressed=true] { background: var(--beui-muted); }
.chart-demo > footer { margin-top: 24px; text-align: center; color: var(--beui-muted-foreground); font-size: 11px; }
.chart-demo .sim { margin-left: 6px; border: 1px solid var(--beui-border); padding: 2px 5px; border-radius: 3px; text-transform: uppercase; font-size: 9px; letter-spacing: .05em; color: var(--beui-muted-foreground); }
</style>
<style scoped>fieldset { display: inline-flex; border: none; margin: 0 0 24px; padding: 4px; border-radius: 24px; background: var(--beui-card); }</style>

API ​

stages 提供有序的阶段、标识和值,direction 切换方向。交互读数展示相较前一步的变化、转换率与总转换率。

还原验收 ​

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