Bump Chart
跟踪序列排名随时间的变化,并固定某条序列以便检查。
适用场景
- 当界面需要以下行为时使用 Bump Chart:跟踪序列排名随时间的变化,并固定某条序列以便检查。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/bump-chart.json https://orvui.efu.me/r/button.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
The leaderboard
Five products. Six months. Every move.
| Series | Apr | May | Jun | Jul | Aug | Sep |
|---|---|---|---|---|---|---|
| Studio | 4 | 3 | 2 | 3 | 2 | 1 |
| Canvas | 1 | 1 | 3 | 2 | 1 | 2 |
| Layers | 3 | 2 | 1 | 1 | 3 | 3 |
| Orbit | 2 | 4 | 5 | 4 | 5 | 4 |
| Frame | 5 | 5 | 4 | 5 | 4 | 5 |
Inspect a dot for details · Select to pin a product
packages/vue/src/charts/bump-chart/demo.vue
<script setup lang="ts">
import { ref } from "vue";
import { Shuffle } from "lucide-vue-next";
import { Button } from "@/components/orvui/motion/button";
import { BumpChart } from "@/components/orvui/charts/bump-chart";
const periods = ["Apr", "May", "Jun", "Jul", "Aug", "Sep"];
const series = ref([
{ id: "studio", name: "Studio", ranks: [4, 3, 2, 3, 2, 1], color: "#8b5cf6" },
{ id: "canvas", name: "Canvas", ranks: [1, 1, 3, 2, 1, 2], color: "#0d9488" },
{ id: "layers", name: "Layers", ranks: [3, 2, 1, 1, 3, 3], color: "#f59e0b" },
{ id: "orbit", name: "Orbit", ranks: [2, 4, 5, 4, 5, 4], color: "#3b82f6" },
{ id: "frame", name: "Frame", ranks: [5, 5, 4, 5, 4, 5], color: "#f43f5e" },
]);
function shuffle() {
const columns = periods.map(() => {
const order = series.value.map((_, index) => index + 1);
for (let remaining = order.length; remaining > 1; remaining--) {
const index = Math.floor(Math.random() * remaining);
[order[index], order[remaining - 1]] = [
order[remaining - 1],
order[index],
];
}
return order;
});
series.value = series.value.map((row, index) => ({
...row,
ranks: columns.map((column) => column[index]),
}));
}
</script>
<template>
<div class="w-full space-y-6">
<div class="flex flex-wrap items-center justify-between gap-4 px-2">
<div>
<h3 class="text-sm font-medium text-foreground">The leaderboard</h3>
<p class="mt-1 text-xs text-muted-foreground">
Five products. Six months. Every move.
</p>
</div>
<Button variant="ghost" size="sm" class="shrink-0 gap-2" @click="shuffle"
><Shuffle class="size-3.5" aria-hidden="true" />Shuffle rankings</Button
>
</div>
<BumpChart
:series="series"
:periods="periods"
label="Illustrative product rankings, April to September"
/>
<p class="text-center text-[11px] text-muted-foreground">
Inspect a dot for details · Select to pin a product
</p>
</div>
</template>
packages/vue/src/charts/bump-chart/src/BumpChart.vue
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
BumpChart | v-model:activenull | string | update:active |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
BumpChart
seriesreadonly BumpSeries[]—periodsreadonly string[]—active?null | string—defaultActive?null | stringnulllabel?string"Rankings over time"className?string—事件
update:active—@update:activeactiveChange—@activeChange插槽
default() => VNodeChild#defaultBumpChartPlot
className?string—BumpChartLegend
className?string—无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Bump Chart?
- 通过 series、periods、active、defaultActive、label、className 配置 Bump Chart;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:active、activeChange,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1