Funnel Chart
跟踪连续阶段,并检查相邻步骤之间的转化与流失。
适用场景
- 当界面需要以下行为时使用 Funnel Chart:跟踪连续阶段,并检查相邻步骤之间的转化与流失。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/funnel-chart.json https://orvui.efu.me/r/button.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
From first visit to first payment
Product conversion · Sample cohorts
Visitors100.0%Signed up65.0%Activated45.0%Started trial30.0%Subscribed18.0%
24,000 → 4,320 peopleOverall conversion18.0%
Inspect a stage to see conversion and drop-off
packages/vue/src/charts/funnel-chart/demo.vue
<script setup lang="ts">
import { computed, ref } from "vue";
import { RefreshCw } from "lucide-vue-next";
import { Button } from "@/components/orvui/motion/button";
import { FunnelChart } from "@/components/orvui/charts/funnel-chart";
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 direction = ref<"vertical" | "horizontal">("vertical");
const cohort = ref(0);
const stages = computed(() =>
labels.map((label, index) => ({
id: label,
label,
value: cohorts[cohort.value][index],
})),
);
const directions = ["vertical", "horizontal"] as const;
function nextCohort() {
cohort.value = (cohort.value + 1) % cohorts.length;
}
</script>
<template>
<div class="w-full space-y-6">
<div class="flex flex-wrap items-center justify-between gap-4">
<div>
<h3 class="text-sm font-medium">From first visit to first payment</h3>
<p class="mt-1 text-xs text-muted-foreground">
Product conversion · Sample cohorts
</p>
</div>
<Button variant="ghost" size="sm" class="gap-2" @click="nextCohort"
><RefreshCw class="size-3.5" aria-hidden="true" />Next cohort</Button
>
</div>
<fieldset
aria-label="Funnel direction"
class="inline-flex gap-1 rounded-full bg-muted/50 p-1"
>
<Button
v-for="orientation in directions"
:key="orientation"
variant="ghost"
size="sm"
:aria-pressed="direction === orientation"
:class="
direction === orientation
? 'bg-background shadow-sm'
: 'text-muted-foreground'
"
@click="direction = orientation"
>{{ orientation === "vertical" ? "Vertical" : "Horizontal" }}</Button
>
</fieldset>
<FunnelChart :direction="direction" :stages="stages" />
<p class="text-center text-[11px] text-muted-foreground">
Inspect a stage to see conversion and drop-off
</p>
</div>
</template>
packages/vue/src/charts/funnel-chart/src/FunnelChart.vue
状态与事件
此示例组合没有声明成对的受控属性与 update 事件。使用已列出的属性、原生事件和插槽组合内容;不要为它添加未公开的 v-model。
API 参考
stagesreadonly FunnelStage[]—direction?"vertical" | "horizontal""vertical"unit?string"people"label?string"Conversion funnel"formatValue?(value: number) => stringformatNumberclassName?string—插槽
default() => VNodeChild#default无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Funnel Chart?
- 通过 stages、direction、unit、label、formatValue、className 配置 Funnel Chart;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 通过default 插槽提供内容,应用副作用由调用方管理。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1