跳到内容

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>-

要在散点图中显示的 series。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

用于着色多个 series 的调色板。

datasetArray<object>-

对象数组,可用于使用其 dataKey 属性填充 series 和坐标轴数据。

disableAxisListenerboolfalse

如果为 true,则图表将不会监听鼠标移动事件。这可能会破坏交互功能,但会提高性能。

disableVoronoiboolfalse

如果为 true,则交互将不会使用 Voronoi 单元格,而是回退到 hover 事件。

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

在背景中显示笛卡尔网格的选项。

heightnumber-

图表的 px 高度。如果未定义,则采用父元素的高度。

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/> 元素上记录的鼠标事件。或者当 disableVoronoi=true 时,来自散点元素的 Mouse 事件。
  • scatterItemIdentifier 散点项目标识符。
resolveSizeBeforeRenderboolfalse

图表将尝试等待父容器解析其大小,然后再首次渲染。
这在某些情况下很有用,在这些情况下,图表在首次渲染后似乎会增长,例如在网格内部使用时。

rightAxisobject
| string
null

指示在图表右侧显示哪个坐标轴。可以是字符串(坐标轴的 id)或对象 ChartsYAxisProps

skipAnimationbool-

如果为 true,则跳过动画。如果未设置或为 false,则动画会尊重用户的 prefers-reduced-motion 设置。

slotPropsobject{}

用于每个组件 slot 的 props。

slotsobject{}

可覆盖的组件 slot。

有关更多详细信息,请参阅下面的Slots 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-

图表的 px 宽度。如果未定义,则采用父元素的宽度。

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。

Slots

Slot 名称类名默认组件描述
axisContentDefaultChartsAxisTooltipContent用于在由坐标轴事件触发时显示工具提示内容的自定义组件。
axisLabelChartsText用于坐标轴标签的自定义组件。
axisLine'line'用于坐标轴主线的自定义组件。
axisTick'line'用于坐标轴刻度的自定义组件。
axisTickLabelChartsText用于刻度标签的自定义组件。
itemContentDefaultChartsItemTooltipContent用于在由项目事件触发时显示工具提示内容的自定义组件。
legendDefaultChartsLegend图例的自定义渲染。
loadingOverlayChartsLoadingOverlay当图表处于加载状态时渲染的覆盖组件。
noDataOverlayChartsNoDataOverlay当图表没有数据要显示时渲染的覆盖组件。
popperChartsTooltipRoot用于工具提示 popper 的自定义组件。
scatter

源代码

如果您在此页面中找不到信息,请考虑查看组件的实现以获取更多详细信息。