Bump Chart
Vue 已实现 · 还原验收 0/1 · 上游演示 · 固定版本源码
预览
The leaderboard
Five products. Six months. Every move.
用法
vue
<script setup lang="ts">
import { BumpChart } from 'beui-vue'
import { shallowRef } from 'vue'
const periods = ['Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep']
const series = shallowRef([
{ 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 ranks = series.value.map((_, index) => index + 1)
for (let from = ranks.length - 1; from > 0; from--) {
const to = Math.floor(Math.random() * (from + 1))
;[ranks[from], ranks[to]] = [ranks[to], ranks[from]]
}
return ranks
})
series.value = series.value.map((row, index) => ({ ...row, ranks: columns.map(column => column[index]) }))
}
</script>
<template>
<div class="chart-demo"><header><div><strong>The leaderboard</strong><p>Five products. Six months. Every move.</p></div><button type="button" @click="shuffle">Shuffle rankings</button></header>
<BumpChart label="Illustrative product rankings, April to September" :series="series" :periods="periods" />
<footer>Inspect a dot for details · Select to pin a product</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>API
series[].ranks 与 periods 对应,缺失名次保留断点,v-model:active 同步固定高亮的系列。