Preview Updated 2026-05-10

ChartToolbar

Chart header bar — title + legend toggles + zoom / export / refresh buttons.

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.

背景

系统资源

last 24h · 1m sampling
  • CPU
  • Memory
图表区
<script setup lang="ts">
import { CfChartToolbar } from '@chufix-design/vue';
const series = [
  { name: 'CPU', colorIndex: 0 },
  { name: 'Memory', colorIndex: 1 },
  { name: 'Disk', colorIndex: 2, hidden: true },
];
</script>

<template>
  <div style="border: 1px solid var(--line-1); border-radius: var(--r-6); overflow: hidden;">
    <CfChartToolbar
      title="系统资源"
      subtitle="last 24h · 1m sampling"
      :series="series"
      show-zoom
      show-export
      show-refresh
      @series-toggle="(name) => alert(`Toggle: ${name}`)"
      @action="(kind) => alert(`Action: ${kind}`)"
    />
    <div style="height: 80px; background: var(--bg-inset); display: flex; align-items: center; justify-content: center; color: var(--fg-3);">图表区</div>
  </div>
</template>
<CfChartToolbar ... />

Live interaction

Click a legend chip to toggle a series; the LineChart below redraws in real time.

背景

系统资源

last 10m · live
  • CPU
  • Memory
CPUMemory20355065800123456789
<script setup lang="ts">
import { computed, ref } from 'vue';
import { CfChartToolbar, CfLineChart } from '@chufix-design/vue';
const series = ref([
  { name: 'CPU', colorIndex: 0, hidden: false, data: [20, 35, 30, 50, 65, 45, 60, 75, 65, 80] },
  { name: 'Memory', colorIndex: 1, hidden: false, data: [40, 38, 50, 55, 60, 58, 62, 68, 72, 70] },
  { name: 'Disk', colorIndex: 2, hidden: true, data: [10, 12, 14, 18, 22, 25, 28, 32, 30, 35] },
]);
const visible = computed(() => series.value.filter((s) => !s.hidden));
function toggle(name: string) {
  series.value = series.value.map((s) =>
    s.name === name ? { ...s, hidden: !s.hidden } : s,
  );
}
</script>

<template>
  <div style="border: 1px solid var(--line-1); border-radius: var(--r-6); overflow: hidden;">
    <CfChartToolbar
      title="系统资源"
      subtitle="last 10m · live"
      :series="series"
      show-zoom
      show-export
      show-refresh
      @series-toggle="(name: string) => toggle(name)"
      @action="(kind: string) => alert(`Action: ${kind}`)"
    />
    <div style="padding: 12px;">
      <CfLineChart :series="visible" :height="180" smooth />
    </div>
  </div>
</template>
<CfChartToolbar series={series} onSeriesToggle={toggle} />
<CfLineChart series={visibleSeries} />

API

PropTypeDefaultDescription
title / subtitlestringTitle and description
seriesLegendSeries[]{ name, colorIndex, hidden? }[]; clicking a legend item triggers toggle
showZoom / showExport / showRefreshbooleanfalseShow button slots

反馈与讨论

ChartToolbar · Discussion

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