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

ScatterPlot 散点图

二维散点,可按 group 分色。

基础用法

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

背景
<script setup lang="ts">
import { CfScatterPlot } from '@chufix-design/vue';
const data = Array.from({ length: 60 }, (_, i) => ({
  x: Math.random() * 100,
  y: Math.random() * 100,
  group: i % 4 === 0 ? 'a' : i % 4 === 1 ? 'b' : i % 4 === 2 ? 'c' : 'd',
}));
</script>

<template>
  <CfScatterPlot :data="data" />
</template>
<CfScatterPlot ... />

多 group 聚类

点的 group 字段决定颜色,未传则归到 default

背景
<script setup lang="ts">
import { CfScatterPlot } from '@chufix-design/vue';
function gen(n: number, group: string, cx: number, cy: number, spread = 20) {
  return Array.from({ length: n }, () => ({
    x: cx + (Math.random() - 0.5) * spread,
    y: cy + (Math.random() - 0.5) * spread,
    group,
  }));
}
const data = [
  ...gen(30, 'cluster-a', 30, 30),
  ...gen(30, 'cluster-b', 70, 60),
  ...gen(30, 'cluster-c', 50, 85),
  ...gen(20, 'outliers', 80, 20, 40),
];
</script>

<template>
  <CfScatterPlot :data="data" />
</template>
<CfScatterPlot data={points} />

API

属性类型默认值说明
dataScatterPoint[]{ x, y, r?, group? }[]
width / heightnumber480 / 240

反馈与讨论

ScatterPlot 散点图 的讨论

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