Skip to content
API 风格:

Chart チャート ​

LhChart はサードパーティ依存ゼロの自研チャートコンポーネントです。折れ線、棒、面、円、ドーナツの 5 種類をサポートし、 内部はフレームワーク非依存の純 SVG レンダリングエンジン(@lh-ui/share/core/chart)です。系列色は --lh-chart-* CSS 変数を使用し、 ライト / ダークテーマや ConfigProvider のコンポーネントレベル上書きと自然に統一されます。サイズは ECharts の必要に応じた導入の約 6% です。

基本的な使い方(折れ線チャート) ​

折れ線チャート type=「line」:カテゴリーラベル + 複数系列
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="line"
    :data="{
      labels: ['1月', '2月', '3月', '4月', '5月', '6月'],
      series: [
        { name: '売上', data: [30, 60, 45, 80, 65, 95] },
        { name: 'コスト', data: [20, 40, 35, 50, 45, 60] },
      ],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="line"
    :data="{
      labels: ['1月', '2月', '3月', '4月', '5月', '6月'],
      series: [
        { name: '売上', data: [30, 60, 45, 80, 65, 95] },
        { name: 'コスト', data: [20, 40, 35, 50, 45, 60] },
      ],
    }"
  />
</template>

棒チャートと積み上げ ​

棒チャート type=「bar」:stack で積み上げ、round で角丸柱
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="bar"
    stack
    round
    :data="{
      labels: ['Q1', 'Q2', 'Q3', 'Q4'],
      series: [
        { name: '華東', data: [120, 150, 140, 180] },
        { name: '華北', data: [80, 95, 110, 130] },
      ],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="bar"
    stack
    round
    :data="{
      labels: ['Q1', 'Q2', 'Q3', 'Q4'],
      series: [
        { name: '華東', data: [120, 150, 140, 180] },
        { name: '華北', data: [80, 95, 110, 130] },
      ],
    }"
  />
</template>

面チャートとスムーズ曲線 ​

面チャート type=「area」+ smooth:単調三次ベジェ、オーバーシュート防止
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="area"
    smooth
    :data="{
      labels: ['月曜', '火曜', '水曜', '木曜', '金曜'],
      series: [{ name: 'アクティブユーザー', data: [820, 932, 901, 1034, 1290] }],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="area"
    smooth
    :data="{
      labels: ['月曜', '火曜', '水曜', '木曜', '金曜'],
      series: [{ name: 'アクティブユーザー', data: [820, 932, 901, 1034, 1290] }],
    }"
  />
</template>

円チャートとドーナツチャート ​

円 / ドーナツチャート type=「pie」「donut」:先頭系列を使用、扇区の割合は凡例クリックで非表示可能
vue
<script setup lang="ts">
import { LhChart } from '@lh-ui/vue3'
</script>

<template>
  <LhChart
    type="donut"
    :data="{
      labels: ['直接アクセス', '検索エンジン', '外部リンク', 'その他'],
      series: [{ name: 'アクセス元', data: [335, 310, 234, 135] }],
    }"
  />
</template>
vue
<script>
export default {}
</script>

<template>
  <LhChart
    type="donut"
    :data="{
      labels: ['直接アクセス', '検索エンジン', '外部リンク', 'その他'],
      series: [{ name: 'アクセス元', data: [335, 310, 234, 135] }],
    }"
  />
</template>

空状態と読み込み ​

loading 読み込みマスク。空データは空状態のプレースホルダーをレンダリング
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhChart } from '@lh-ui/vue3'

const loading = ref(true)
const data = ref({ labels: [], series: [] })
</script>

<template>
  <LhChart loading :data="data" />
</template>
vue
<script>
export default {
  data() {
    return { loading: true, data: { labels: [], series: [] } }
  },
}
</script>

<template>
  <LhChart :loading="loading" :data="data" />
</template>

API ​

Props ​

プロパティ説明型デフォルト値
typeチャートのタイプ'line' | 'bar' | 'area' | 'pie' | 'donut''line'
dataチャートデータ(カテゴリーラベル + 系列。pie / donut は先頭系列を使用)LhChartData—
heightキャンバスの高さ pxnumber320
smooth折れ線 / 面のスムーズ化(単調ベジェ、オーバーシュート防止)booleanfalse
stack積み上げ(bar / area のみ。負の値は 0 として計上)booleanfalse
round柱の角丸(bar のみ)booleanfalse
legend凡例(クリックで系列の表示 / 非表示を切替)booleantrue
tooltipホバーツールチップ(カテゴリーに吸着)booleantrue
gridグリッド線と軸ラベルbooleantrue
animated入場アニメーション(初回レンダリング時のみ)booleantrue
precision数値の小数点桁数上限number2
innerRadius円チャートの内半径比率(donut のデフォルトは 0.6)number0
loading読み込みマスクbooleanfalse
ariaLabelアクセシビリティ名(未指定時はデータからフォールバック)string—
themeVarsコンポーネントレベルのテーマ変数(キーに自動で --lh- プレフィックスを付加)Record<string, string>—
sxsx クイックレイアウトプロパティLhSxProps—

Events ​

イベント名説明コールバック
legend-change凡例をクリックして系列の表示 / 非表示を切り替えた時に発火(legend: { name: string; hidden: boolean }[])

data データ構造 ​

ts
interface LhChartData {
  /** カテゴリーラベル。欠落時はインデックスでフォールバック */
  labels?: string[]
  /** データ系列。pie / donut は先頭系列を使用 */
  series: { name: string; data: number[]; color?: string }[]
}

アクセシビリティ ​

  • ルートノードに role="img" + aria-label(ariaLabel 未指定時はチャートタイプ + 系列名からフォールバック)
  • 視覚的に隠れた生データテーブル(.lh-chart__sr-table)を内蔵し、スクリーンリーダーがすべての数値をそのまま読取可能
  • 凡例項目はネイティブ button + aria-pressed でキーボード操作可能
  • システムで「動きを減らす」が有効な場合、入場アニメーションをスキップ(prefers-reduced-motion)

国風の美で、コードの基を築く