跳至內容

ScatterChartAPI

React ScatterChart 元件的 API 參考文件。瞭解此匯出模組的 props、CSS 和其他 API。

示範

匯入

import { ScatterChart } from '@mui/x-charts/ScatterChart';
// or
import { ScatterChart } from '@mui/x-charts';
// or
import { ScatterChart } from '@mui/x-charts-pro';

閱讀關於最小化套件大小的指南,以瞭解差異。

Props

原生元件的 Props 也可用。

名稱類型預設值描述
series*Array<object>-

要在散佈圖中顯示的系列。 ScatterSeriesType 物件的陣列。

axisHighlight{ x?: 'band'
| 'line'
| 'none', y?: 'band'
| 'line'
| 'none' }
{ x: 'none', y: 'none' }

座標軸醒目提示的設定。

請參閱醒目提示文件以瞭解更多詳細資訊。

bottomAxisobject
| string
xAxisIds[0] 第一個提供的座標軸的 ID

指示要顯示圖表底部的哪個座標軸。可以是字串(座標軸的 ID)或物件 ChartsXAxisProps

colorsArray<string>
| func
blueberryTwilightPalette

用於為多個系列著色的調色盤。

datasetArray<object>-

物件陣列,可用於使用其 dataKey 屬性來填入系列和座標軸資料。

disableAxisListenerboolfalse

如果為 true,圖表將不會監聽滑鼠移動事件。這可能會破壞互動功能,但會提高效能。

disableVoronoiboolfalse

如果為 true,則互動將不會使用 Voronoi 單元格,並退回至 hover 事件。

grid{ horizontal?: bool, vertical?: bool }-

在背景中顯示笛卡爾網格的選項。

heightnumber-

圖表的像素高度。如果未定義,則採用父元素的高度。

highlightedItem{ dataIndex?: number, seriesId?: number
| string }
-

目前醒目提示的項目。將醒目提示變成受控 prop。

leftAxisobject
| string
yAxisIds[0] 第一個提供的座標軸的 ID

指示要顯示圖表左側的哪個座標軸。可以是字串(座標軸的 ID)或物件 ChartsYAxisProps

loadingboolfalse

如果為 true,則會顯示載入覆蓋層。

margin{ bottom?: number, left?: number, right?: number, top?: number }object 取決於圖表類型。

SVG 和繪圖區域之間的邊界。它用於為額外資訊(例如 x 軸和 y 軸或圖例)保留一些空間。接受具有可選屬性的物件:topbottomleftright

onHighlightChangefunc-

醒目提示項目變更時觸發的回呼。

簽名:function(highlightedItem: HighlightItemData | null) => void
  • highlightedItem 新醒目提示的項目。
onItemClickfunc-

點擊散佈圖項目時觸發的回呼。

簽名:function(event: MouseEvent, scatterItemIdentifier: ScatterItemIdentifier) => void
  • event 如果使用 Voronoi 單元格,則在 <svg/> 元素上記錄的滑鼠事件。或者來自散佈圖元素的 Mouse 事件,當 disableVoronoi=true 時。
  • scatterItemIdentifier 散佈圖項目識別符。
resolveSizeBeforeRenderboolfalse

圖表將嘗試等待父容器解析其大小,然後再首次呈現。
這在某些情況下很有用,例如在網格內使用時,圖表在首次呈現後似乎會成長。

rightAxisobject
| string
null

指示要顯示圖表右側的哪個座標軸。可以是字串(座標軸的 ID)或物件 ChartsYAxisProps

skipAnimationbool-

如果為 true,則會跳過動畫。如果未設定或為 false,則動畫會遵循使用者的 prefers-reduced-motion 設定。

slotPropsobject{}

用於每個元件插槽的 props。

slotsobject{}

可覆寫的元件插槽。

請參閱下方的插槽 API 以瞭解更多詳細資訊。

tooltip{ axisContent?: elementType, classes?: object, itemContent?: elementType, slotProps?: object, slots?: object, trigger?: 'axis'
| 'item'
| 'none' }
{ trigger: 'item' }

工具提示的設定。

請參閱工具提示文件以瞭解更多詳細資訊。

topAxisobject
| string
null

指示要顯示圖表頂部的哪個座標軸。可以是字串(座標軸的 ID)或物件 ChartsXAxisProps

voronoiMaxRadiusnumber-

定義散佈點與觸發互動的指標之間的最大距離。如果 undefined,則假定半徑為無限大。

widthnumber-

圖表的像素寬度。如果未定義,則採用父元素的寬度。

xAxisArray<{ classes?: object, colorMap?: { colors: Array<string>, type: 'ordinal', unknownColor?: string, values?: Array<Date
| number
| string> }
| { color: Array<string>
| func, max?: Date
| number, min?: Date
| number, type: 'continuous' }
| { colors: Array<string>, thresholds: Array<Date
| number>, type: 'piecewise' }, data?: array, dataKey?: string, disableLine?: bool, disableTicks?: bool, domainLimit?: 'nice'
| 'strict'
| func, fill?: string, hideTooltip?: bool, id?: number
| string, label?: string, labelFontSize?: number, labelStyle?: object, max?: Date
| number, min?: Date
| number, position?: 'bottom'
| 'top', reverse?: bool, scaleType?: 'band'
| 'linear'
| 'log'
| 'point'
| 'pow'
| 'sqrt'
| 'time'
| 'utc', slotProps?: object, slots?: object, stroke?: string, sx?: Array<func
| object
| bool>
| func
| object, tickFontSize?: number, tickInterval?: 'auto'
| array
| func, tickLabelInterval?: 'auto'
| func, tickLabelPlacement?: 'middle'
| 'tick', tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickPlacement?: 'end'
| 'extremities'
| 'middle'
| 'start', tickSize?: number, valueFormatter?: func }>
-

x 軸的設定。如果未提供,則會使用預設座標軸設定。 AxisConfig 物件的陣列。

yAxisArray<{ classes?: object, colorMap?: { colors: Array<string>, type: 'ordinal', unknownColor?: string, values?: Array<Date
| number
| string> }
| { color: Array<string>
| func, max?: Date
| number, min?: Date
| number, type: 'continuous' }
| { colors: Array<string>, thresholds: Array<Date
| number>, type: 'piecewise' }, data?: array, dataKey?: string, disableLine?: bool, disableTicks?: bool, domainLimit?: 'nice'
| 'strict'
| func, fill?: string, hideTooltip?: bool, id?: number
| string, label?: string, labelFontSize?: number, labelStyle?: object, max?: Date
| number, min?: Date
| number, position?: 'left'
| 'right', reverse?: bool, scaleType?: 'band'
| 'linear'
| 'log'
| 'point'
| 'pow'
| 'sqrt'
| 'time'
| 'utc', slotProps?: object, slots?: object, stroke?: string, sx?: Array<func
| object
| bool>
| func
| object, tickFontSize?: number, tickInterval?: 'auto'
| array
| func, tickLabelInterval?: 'auto'
| func, tickLabelPlacement?: 'middle'
| 'tick', tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickPlacement?: 'end'
| 'extremities'
| 'middle'
| 'start', tickSize?: number, valueFormatter?: func }>
-

y 軸的設定。如果未提供,則會使用預設座標軸設定。 AxisConfig 物件的陣列。

zAxisArray<{ colorMap?: { colors: Array<string>, type: 'ordinal', unknownColor?: string, values?: Array<Date
| number
| string> }
| { color: Array<string>
| func, max?: Date
| number, min?: Date
| number, type: 'continuous' }
| { colors: Array<string>, thresholds: Array<Date
| number>, type: 'piecewise' }, data?: array, dataKey?: string, id?: string, max?: number, min?: number }>
-

z 軸的設定。

ref 會轉發到根元素。

主題預設 props

您可以使用 MuiScatterChart 透過主題變更此元件的預設 props。

插槽

插槽名稱類別名稱預設元件描述
axisContentDefaultChartsAxisTooltipContent用於在由座標軸事件觸發時顯示工具提示內容的客製化元件。
axisLabelChartsText座標軸標籤的客製化元件。
axisLine'line'用於座標軸主線的客製化元件。
axisTick'line'用於座標軸刻度的客製化元件。
axisTickLabelChartsText用於刻度標籤的客製化元件。
itemContentDefaultChartsItemTooltipContent用於在由項目事件觸發時顯示工具提示內容的客製化元件。
legendDefaultChartsLegend圖例的客製化呈現。
loadingOverlayChartsLoadingOverlay當圖表處於載入狀態時呈現的覆蓋層元件。
noDataOverlayChartsNoDataOverlay當圖表沒有資料可顯示時呈現的覆蓋層元件。
popperChartsTooltipRoot用於工具提示 popper 的客製化元件。
scatter

原始碼

如果您在本頁中找不到資訊,請考慮查看元件的實作以瞭解更多詳細資訊。