Skip to content

Biểu Đồ Phân Tán

Hiển thị phân bố và phân tích tương quan với biểu đồ phân tán và biểu đồ bong bóng tùy chỉnh.

Loading chart...

Cài Đặt

bash
npx @galaxy-stack/nebula-cli@latest add scatter-chart
bash
pnpm dlx @galaxy-stack/nebula-cli@latest add scatter-chart
bash
yarn dlx @galaxy-stack/nebula-cli@latest add scatter-chart
bash
bunx @galaxy-stack/nebula-cli@latest add scatter-chart
bash
# Nếu bạn đã cài đặt galaxy-design toàn cục
galaxy-design add scatter-chart

Dependencies

Component này tự động cài đặt các dependencies sau:

  • Vue: vue-echarts@^7.0.3, echarts@^5.5.1
  • React: echarts-for-react@^3.0.2, echarts@^5.5.1
  • Angular: ngx-echarts@^18.0.0, echarts@^5.5.1
  • React Native: @wuba/react-native-echarts@^3.0.1, echarts@^5.5.1, @shopify/react-native-skia@^1.6.4
  • Flutter: fl_chart@^0.68.0

Không cần cài đặt thủ công!

Sử Dụng

Biểu Đồ Phân Tán Cơ Bản

vue
<script setup lang="ts">
import { ScatterChart } from '@/components/ui/charts'

const data = {
  datasets: [{
    label: 'Dữ Liệu',
    data: [
      [10, 20], [15, 25], [20, 30], [25, 35], [30, 40]
    ],
    color: '#3b82f6'
  }]
}
</script>

<template>
  <ScatterChart :data="data" :height="300" />
</template>
tsx
import { ScatterChart } from "@/components/ui/charts"

const data = {
  datasets: [{
    label: 'Dữ Liệu',
    data: [
      [10, 20], [15, 25], [20, 30], [25, 35], [30, 40]
    ],
    color: '#3b82f6'
  }]
}

export default function App() {
  return <ScatterChart data={data} height={300} />
}

Biểu Đồ Phân Tán Với Multiple Datasets

vue
<script setup lang="ts">
const multiData = {
  datasets: [
    { label: 'Nhóm A', data: [[10, 20], [15, 25], [20, 30]], color: '#3b82f6' },
    { label: 'Nhóm B', data: [[12, 50], [18, 45], [22, 40]], color: '#10b981' },
    { label: 'Nhóm C', data: [[25, 35], [30, 30], [35, 25]], color: '#f59e0b' }
  ]
}
</script>

<template>
  <ScatterChart :data="multiData" :height="300" />
</template>
tsx
const multiData = {
  datasets: [
    { label: 'Nhóm A', data: [[10, 20], [15, 25], [20, 30]], color: '#3b82f6' },
    { label: 'Nhóm B', data: [[12, 50], [18, 45], [22, 40]], color: '#10b981' },
    { label: 'Nhóm C', data: [[25, 35], [30, 30], [35, 25]], color: '#f59e0b' }
  ]
}

<ScatterChart data={multiData} height={300} />

Biểu Đồ Bong Bóng (Bubble Chart)

vue
<script setup lang="ts">
const bubbleData = {
  datasets: [{
    label: 'Bong Bóng',
    data: [
      [10, 20, 15], [15, 25, 20], [20, 30, 25], [25, 35, 30]
    ],
    color: '#3b82f6'
  }]
}
</script>

<template>
  <ScatterChart :data="bubbleData" :height="300" :bubble="true" />
</template>
tsx
const bubbleData = {
  datasets: [{
    label: 'Bong Bóng',
    data: [
      [10, 20, 15], [15, 25, 20], [20, 30, 25], [25, 35, 30]
    ],
    color: '#3b82f6'
  }]
}

<ScatterChart data={bubbleData} height={300} bubble />

Biểu Đồ Với Custom Axes

vue
<ScatterChart
  :data="data"
  :height="300"
  xAxisLabel="Doanh Thu (triệu)"
  yAxisLabel="Lợi Nhuận (%)"
  :xMin="0"
  :xMax="100"
  :yMin="0"
  :yMax="100"
/>
tsx
<ScatterChart
  data={data}
  height={300}
  xAxisLabel="Doanh Thu (triệu)"
  yAxisLabel="Lợi Nhuận (%)"
  xMin={0}
  xMax={100}
  yMin={0}
  yMax={100}
/>

API Reference

Props

PropTypeDefaultMô Tả
dataChartDatarequiredDữ liệu biểu đồ với datasets
heightnumber300Chiều cao biểu đồ (pixels)
widthnumber | string'100%'Chiều rộng biểu đồ
theme'light' | 'dark''light'Chủ đề màu sắc
bubblebooleanfalseHiển thị chế độ bong bóng
xAxisLabelstring''Nhãn trục X
yAxisLabelstring''Nhãn trục Y
xMinnumber0Giá trị tối thiểu trục X
xMaxnumber100Giá trị tối đa trục X
yMinnumber0Giá trị tối thiểu trục Y
yMaxnumber100Giá trị tối đa trục Y
showGridbooleantrueHiển thị lưới
legendbooleantrueHiển thị chú thích
legendPosition'top' | 'bottom' | 'left' | 'right''top'Vị trí chú thích
animationbooleantrueBật/tắt animation
loadingbooleanfalseHiển thị trạng thái loading
emptyTextstring'Không có dữ liệu'Thông báo khi không có dữ liệu

ChartData Interface

typescript
interface ChartData {
  datasets: ChartDataset[]
}

interface ChartDataset {
  label: string
  data: number[][] | [number, number, number][] // [x, y] hoặc [x, y, size]
  color?: string
}

Use Cases

  • Phân Tích Tương Quan - Tìm mối quan hệ giữa hai biến
  • Phân Bố Dữ Liệu - Hiển thị distribution patterns
  • So Sánh Nhóm - So sánh multiple groups
  • Phát Hiện Outliers - Xác định điểm dữ liệu bất thường
  • Nghiên Cứu Khoa Học - Trực quan hóa experimental data

Best Practices

1. Sử Dụng Cho Dữ Liệu Phân Tán

vue
<!-- ✅ Tốt cho scatter/bubble data -->
<ScatterChart :data="scatterData" />

<!-- ❌ Không dùng cho data có labels -->
<ScatterChart :data="labeledData" />

2. Chọn Scale Phù Hợp

vue
<!-- ✅ Chọn range phù hợp với dữ liệu -->
<ScatterChart :data="data" :xMin="0" :xMax="100" :yMin="0" :yMax="100" />

<!-- ❌ Tránh range quá rộng -->
<ScatterChart :data="data" :xMin="0" :xMax="10000" />

3. Sử Dụng Bubble Cho 3 Dimensions

vue
<!-- ✅ Sử dụng bubble cho x, y, size -->
<ScatterChart :data="bubbleData" bubble />

4. Responsive Design

vue
<template>
  <div class="w-full aspect-video">
    <ScatterChart :data="data" />
  </div>
</template>

Accessibility

  • Screen Reader: Mô tả văn bản thay thế cho dữ liệu
  • Keyboard Navigation: Điều hướng bằng bàn phím
  • Color Contrast: Tỷ lệ tương phản màu sắc đạt chuẩn
  • Focus Indicators: Chỉ báo focus rõ ràng

Các Ví Dụ Khác

Biểu Đồ Với Grid Lines

vue
<ScatterChart :data="data" :height="300" :showGrid="true" />
tsx
<ScatterChart data={data} height={300} showGrid />

Biểu Đồ Với Legend Bottom

vue
<ScatterChart :data="data" :height="300" legendPosition="bottom" />
tsx
<ScatterChart data={data} height={300} legendPosition="bottom" />

Framework Support

FrameworkThư ViệnVersion
VueECharts^5.5.1
ReactECharts for React^3.0.2
Angularngx-echarts^18.0.0
React Native@wuba/react-native-echarts^3.0.1
Flutterfl_chart^0.68.0

Các Trang Liên Quan

Phát hành theo Giấy phép MIT.