Skip to content

ChartStatCard 指标卡

指标卡用于首页概览、经营看板、健康摘要和账户概览。它把标题、主数值、单位、趋势标签、辅助描述和迷你趋势图组合成一个完整信息单元。

直接 Demo

项目内置可运行示例位于 src/components/demos/chart-stat-card-demo.vue,文档预览、preview catalog 与 showcase 都使用这个独立 Demo,不再借用 chart-lite 聚合页。

基础用法

vue
<template>
  <lk-chart-stat-card
    title="今日步数"
    value="12,680"
    unit="steps"
    description="比上周同日更活跃"
    trend="up"
    trend-text="+18%"
    :data="steps"
  />
</template>

<script setup lang="ts">
const steps = [
  { label: 'Mon', value: 6800 },
  { label: 'Tue', value: 7600 },
  { label: 'Wed', value: 7300 },
  { label: 'Thu', value: 9100 },
  { label: 'Fri', value: 10200 },
  { label: 'Sat', value: 11800 },
  { label: 'Sun', value: 12600 },
];
</script>

无图模式

vue
<lk-chart-stat-card
  title="转化率"
  value="18.6"
  unit="%"
  trend="flat"
  trend-text="稳定"
  :show-chart="false"
/>

自定义图表色

color 只影响内嵌迷你趋势线,不影响标题、主数值、单位、趋势文案和辅助描述。文本默认使用中性色 token,避免在业务卡片中被品牌色过度染色。

vue
<lk-chart-stat-card
  title="净收入"
  value="71k"
  trend="up"
  trend-text="+8.6%"
  :data="revenue"
  color="#2563eb"
/>

数据格式

ts
interface LiteChartPoint {
  label?: string;
  value: number;
}

Props

参数说明类型默认值
title指标标题string''
value主数值string / number''
unit数值单位string''
description辅助描述string''
trendText趋势文案string''
trend趋势方向up / down / flatflat
data迷你趋势数据LiteChartPoint[][]
showChart是否显示迷你趋势图booleantrue
chartHeight图表高度,数字按 rpx 处理number / string112
chartLineWidth内嵌趋势线线宽,单位 rpxnumber5
chartAnimationDuration内嵌趋势线入场动画时长,单位 msnumber560
chartAnimationRepeat内嵌趋势线入场动画重复次数,0 表示持续循环number1
chartEffect内嵌趋势线动效等级none / subtle / premiumpremium
color内嵌趋势线主色,不影响文本颜色stringprimary

使用建议

  • 主数值由业务侧格式化后传入,组件不负责金额、百分比、千分位格式化。
  • 两列指标卡并排时,保持 titledescription 文案长度接近,避免高度不一致。
  • 数据不足或业务只需要展示 KPI 时,关闭 showChart
  • 需要强调品牌或状态时优先使用图表色、趋势方向和业务文案,不建议把标题、数值整体改成品牌色。
  • 更自由的布局可以用 Card + ChartSparkline 自行组合。

注意事项

TIP

trend 只表达视觉语义,不会自动根据数据计算涨跌;建议服务端或业务层明确给出趋势方向。

基于 MIT 协议开源

ChartStatCard 指标卡

正在连接预览服务...

请先运行 pnpm run dev:h5