Preview Updated 2026-05-10

BarChart

Single-series vertical bar chart.

Basic usage

Data is passed in via props and rendered as plain SVG — no third-party charting library. Colors come from the --viz-1..8 tokens and are color-blind friendly.

背景
023466891MonTueWedThuFriSatSunMonTue
src/App.vue
<script setup lang="ts">
import { CfBarChart } from '@chufix-design/vue';
const data = [42, 68, 35, 91, 57, 78, 23, 64, 49];
const labels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue'];
</script>
<template>
  <CfBarChart :data="data" :labels="labels" />
</template>
<script setup>
import { CfBarChart } from '@chufix-design/vue';
const data = [42, 68, 35, 91, 57, 78, 23, 64, 49];
const labels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue'];
</script>
<template>
  <CfBarChart :data="data" :labels="labels" />
</template>
import { CfBarChart } from '@chufix-design/react';

export default function Demo() {
  const data = [42, 68, 35, 91, 57, 78, 23, 64, 49];
  const labels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue'];
  return (
    <>
      <CfBarChart data={data} labels={labels} />
    </>
  );
}
import { CfBarChart } from '@chufix-design/react';

export default function Demo() {
  const data = [42, 68, 35, 91, 57, 78, 23, 64, 49];
  const labels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon','Tue'];
  return (
    <>
      <CfBarChart data={data} labels={labels} />
    </>
  );
}

Color

colorIndex 0..7 selects --viz-1..8 directly.

背景
023466891MonTueWedThuFriSatSunMon023466891MonTueWedThuFriSatSunMon023466891MonTueWedThuFriSatSunMon023466891MonTueWedThuFriSatSunMon
src/App.vue
<script setup lang="ts">
import { CfBarChart } from '@chufix-design/vue';
const data = [42, 68, 35, 91, 57, 78, 23, 64];
const labels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon'];
</script>
<template>
  <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 16px;">
    <CfBarChart :data="data" :labels="labels" :color-index="0" :height="180" />
    <CfBarChart :data="data" :labels="labels" :color-index="2" :height="180" />
    <CfBarChart :data="data" :labels="labels" :color-index="3" :height="180" />
    <CfBarChart :data="data" :labels="labels" :color-index="5" :height="180" />
  </div>
</template>
<script setup>
import { CfBarChart } from '@chufix-design/vue';
const data = [42, 68, 35, 91, 57, 78, 23, 64];
const labels = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun','Mon'];
</script>
<template>
  <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 16px;">
    <CfBarChart :data="data" :labels="labels" :color-index="0" :height="180" />
    <CfBarChart :data="data" :labels="labels" :color-index="2" :height="180" />
    <CfBarChart :data="data" :labels="labels" :color-index="3" :height="180" />
    <CfBarChart :data="data" :labels="labels" :color-index="5" :height="180" />
  </div>
</template>
import { CfBarChart } from '@chufix-design/react';

export default function Demo() {
  const data = [42, 68, 35, 91, 57, 78, 23, 64];
  return (
    <>
      <CfBarChart data={data} colorIndex={0} />
      <CfBarChart data={data} colorIndex={3} />
    </>
  );
}
import { CfBarChart } from '@chufix-design/react';

export default function Demo() {
  const data = [42, 68, 35, 91, 57, 78, 23, 64];
  return (
    <>
      <CfBarChart data={data} colorIndex={0} />
      <CfBarChart data={data} colorIndex={3} />
    </>
  );
}

Horizontal layout

Use orientation="horizontal" for rankings, comparisons, or longer category labels.

背景
023466891APIWebDBCacheQueueWorker
src/App.vue
<script setup lang="ts">
import { CfBarChart } from '@chufix-design/vue';

const data = [42, 68, 35, 91, 57, 78];
const labels = ['API', 'Web', 'DB', 'Cache', 'Queue', 'Worker'];
</script>
<template>
  <CfBarChart :data="data" :labels="labels" orientation="horizontal" />
</template>
<script setup>
import { CfBarChart } from '@chufix-design/vue';

const data = [42, 68, 35, 91, 57, 78];
const labels = ['API', 'Web', 'DB', 'Cache', 'Queue', 'Worker'];
</script>
<template>
  <CfBarChart :data="data" :labels="labels" orientation="horizontal" />
</template>
import { CfBarChart } from '@chufix-design/react';

export default function Demo() {
  const data = [42, 68, 35, 91, 57, 78];
  const labels = ['API', 'Web', 'DB', 'Cache', 'Queue', 'Worker'];
  return (
    <>
      <CfBarChart data={data} labels={labels} orientation="horizontal" />
    </>
  );
}
import { CfBarChart } from '@chufix-design/react';

export default function Demo() {
  const data = [42, 68, 35, 91, 57, 78];
  const labels = ['API', 'Web', 'DB', 'Cache', 'Queue', 'Worker'];
  return (
    <>
      <CfBarChart data={data} labels={labels} orientation="horizontal" />
    </>
  );
}

API

PropTypeDefaultDescription
datanumber[]Bar heights
labelsstring[]x-axis labels
colorIndex0..70
orientation'vertical' | 'horizontal''vertical'Bar direction
width / height / showGrid / showLabels

反馈与讨论

BarChart · Discussion

0
0 / 600
一键发送
正在加载评论...