开发预览 更新于 2026-05-10

BulletChart 子弹图

单值进度条 + 目标线 + 质量带,比 Gauge 更适合"对比目标"语义。

基础用法

数据通过 props 传入,纯 SVG 渲染,无第三方图表库依赖。 配色取自 --viz-1..8 token,色盲友好。

背景 视口
src/App.vue
<script setup lang="ts">
import { CfBulletChart } from '@chufix-design/vue';
</script>
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 360px;">
    <CfBulletChart label="收入" :value="780" :target="900" :max="1200" :bands="[{upTo: 400, tone: 'error'}, {upTo: 700, tone: 'warning'}, {upTo: 1200, tone: 'success'}]" />
    <CfBulletChart label="留存率" :value="62" :target="70" :max="100" :bands="[{upTo: 40, tone: 'error'}, {upTo: 70, tone: 'warning'}, {upTo: 100, tone: 'success'}]" />
  </div>
</template>
<script setup>
import { CfBulletChart } from '@chufix-design/vue';
</script>
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 360px;">
    <CfBulletChart label="收入" :value="780" :target="900" :max="1200" :bands="[{upTo: 400, tone: 'error'}, {upTo: 700, tone: 'warning'}, {upTo: 1200, tone: 'success'}]" />
    <CfBulletChart label="留存率" :value="62" :target="70" :max="100" :bands="[{upTo: 40, tone: 'error'}, {upTo: 70, tone: 'warning'}, {upTo: 100, tone: 'success'}]" />
  </div>
</template>
import { CfBulletChart } from '@chufix-design/react';

export default function Demo() {
  return (
    <>
      <div style={{ display: "flex", flexDirection: "column", gap: 12, maxWidth: 360 }}>
          <CfBulletChart label="收入" value={780} target={900} max={1200} bands={[{upTo: 400, tone: 'error'}, {upTo: 700, tone: 'warning'}, {upTo: 1200, tone: 'success'}]} />
          <CfBulletChart label="留存率" value={62} target={70} max={100} bands={[{upTo: 40, tone: 'error'}, {upTo: 70, tone: 'warning'}, {upTo: 100, tone: 'success'}]} />
        </div>
    </>
  );
}
import { CfBulletChart } from '@chufix-design/react';

export default function Demo() {
  return (
    <>
      <div style={{ display: "flex", flexDirection: "column", gap: 12, maxWidth: 360 }}>
          <CfBulletChart label="收入" value={780} target={900} max={1200} bands={[{upTo: 400, tone: 'error'}, {upTo: 700, tone: 'warning'}, {upTo: 1200, tone: 'success'}]} />
          <CfBulletChart label="留存率" value={62} target={70} max={100} bands={[{upTo: 40, tone: 'error'}, {upTo: 70, tone: 'warning'}, {upTo: 100, tone: 'success'}]} />
        </div>
    </>
  );
}

质量带 + 超过目标

bands 三段染色 + target 垂直线,超过目标时 value 条会延伸过 target。

背景 视口
src/App.vue
<script setup lang="ts">
import { CfBulletChart } from '@chufix-design/vue';
</script>
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 360px;">
    <CfBulletChart label="无质量带" :value="65" :target="80" :max="100" />
    <CfBulletChart
      label="3 段质量带"
      :value="65"
      :target="80"
      :max="100"
      :bands="[{upTo: 40, tone: 'error'}, {upTo: 75, tone: 'warning'}, {upTo: 100, tone: 'success'}]"
    />
    <CfBulletChart
      label="超过目标"
      :value="92"
      :target="80"
      :max="100"
      :bands="[{upTo: 50, tone: 'error'}, {upTo: 80, tone: 'warning'}, {upTo: 100, tone: 'success'}]"
    />
  </div>
</template>
<script setup>
import { CfBulletChart } from '@chufix-design/vue';
</script>
<template>
  <div style="display: flex; flex-direction: column; gap: 12px; max-width: 360px;">
    <CfBulletChart label="无质量带" :value="65" :target="80" :max="100" />
    <CfBulletChart
      label="3 段质量带"
      :value="65"
      :target="80"
      :max="100"
      :bands="[{upTo: 40, tone: 'error'}, {upTo: 75, tone: 'warning'}, {upTo: 100, tone: 'success'}]"
    />
    <CfBulletChart
      label="超过目标"
      :value="92"
      :target="80"
      :max="100"
      :bands="[{upTo: 50, tone: 'error'}, {upTo: 80, tone: 'warning'}, {upTo: 100, tone: 'success'}]"
    />
  </div>
</template>
import { CfBulletChart } from '@chufix-design/react';

export default function Demo() {
  return (
    <>
      <div style={{ display: "flex", flexDirection: "column", gap: 12, maxWidth: 360 }}>
          <CfBulletChart label="无质量带" value={65} target={80} max={100} />
          <CfBulletChart label="3 段质量带" value={65} target={80} max={100} bands={[{upTo: 40, tone: 'error'}, {upTo: 75, tone: 'warning'}, {upTo: 100, tone: 'success'}]} />
          <CfBulletChart label="超过目标" value={92} target={80} max={100} bands={[{upTo: 50, tone: 'error'}, {upTo: 80, tone: 'warning'}, {upTo: 100, tone: 'success'}]} />
        </div>
    </>
  );
}
import { CfBulletChart } from '@chufix-design/react';

export default function Demo() {
  return (
    <>
      <div style={{ display: "flex", flexDirection: "column", gap: 12, maxWidth: 360 }}>
          <CfBulletChart label="无质量带" value={65} target={80} max={100} />
          <CfBulletChart label="3 段质量带" value={65} target={80} max={100} bands={[{upTo: 40, tone: 'error'}, {upTo: 75, tone: 'warning'}, {upTo: 100, tone: 'success'}]} />
          <CfBulletChart label="超过目标" value={92} target={80} max={100} bands={[{upTo: 50, tone: 'error'}, {upTo: 80, tone: 'warning'}, {upTo: 100, tone: 'success'}]} />
        </div>
    </>
  );
}

API

属性类型默认值说明
valuenumber当前值
targetnumber目标值(垂直线)
maxnumber最大值
bands{ upTo: number; tone?: 'error' | 'warning' | 'success' }[][]质量带;从左到右染色,配合 upTo 累计
labelstring左侧标签
widthnumber480SVG 宽度
heightnumber32SVG 高度
ariaLabelstring透传给根 <svg>aria-label

Events

Vue 事件React 回调载荷类型说明
clickonClickBulletChartInteractionPayload点击 bullet 区域
item-enteronItemEnterBulletChartInteractionPayload鼠标进入 bullet 区域
item-leaveonItemLeaveBulletChartInteractionPayload鼠标离开 bullet 区域

类型

interface BulletChartInteractionPayload {
  value: number;
  target: number;
  max: number;
  nativeEvent?: PointerEvent | MouseEvent;
}

反馈与讨论

BulletChart 子弹图 的讨论

0
0 / 600
正在加载评论...