SparkLineChartAPI
React SparkLineChart 組件的 API 參考文件。瞭解此匯出模組的 props、CSS 和其他 API。
範例展示
匯入
import { SparkLineChart } from '@mui/x-charts/SparkLineChart';
// or
import { SparkLineChart } from '@mui/x-charts';
// or
import { SparkLineChart } from '@mui/x-charts-pro';
請閱讀本指南,瞭解關於最小化 bundle size 的差異。
也提供原生組件的 Props。
名稱 | 類型 | 預設值 | 描述 |
---|---|---|---|
data* | Array<number> | - | 用於繪製圖表的資料。 |
area | bool | false | 設定為 |
colors | Array<string> | func | blueberryTwilightPalette | 用於為多個系列著色的調色盤。 |
dataset | Array<object> | - | 可用於使用其 |
disableAxisListener | bool | false | 如果為 |
height | number | - | 圖表的高度,單位為 px。如果未定義,則會採用父元素的高度。 |
highlightedItem | { dataIndex?: number, seriesId?: number | string } | - | 目前醒目提示的項目。將醒目提示功能變成受控的 prop。 |
margin | { bottom?: number, left?: number, right?: number, top?: number } | { top: 5, bottom: 5, left: 5, right: 5, } | SVG 和繪圖區域之間的邊距。它用於為額外資訊(例如 x 軸和 y 軸或圖例)保留一些空間。接受具有可選屬性的物件: |
onHighlightChange | func | - | 當醒目提示的項目變更時觸發的回呼函式。 簽名: function(highlightedItem: HighlightItemData | null) => void
|
plotType | 'bar' | 'line' | 'line' | 使用的繪圖類型。 |
resolveSizeBeforeRender | bool | false | 圖表將嘗試等待父容器解析其大小,然後再首次渲染。 |
showHighlight | bool | false | 設定為 |
showTooltip | bool | false | 設定為 |
skipAnimation | bool | - | 如果為 |
slotProps | object | {} | 用於每個組件 slot 的 props。 |
slots | object | {} | 可覆寫的組件 slots。 有關更多詳細資訊,請參閱下方的 Slots API。 |
valueFormatter | func | (value: number | null) => (value === null ? '' : value.toString()) | 工具提示使用的格式化工具。 簽名: function(value: number) => string
傳回值:格式化後的值。 |
width | number | - | 圖表的寬度,單位為 px。如果未定義,則會採用父元素的寬度。 |
xAxis | { 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 } | - | xAxis 設定。請注意,它是一個單一的 AxisConfig 物件,而不是設定陣列。 |
yAxis | { 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 } | - | yAxis 設定。請注意,它是一個單一的 AxisConfig 物件,而不是設定陣列。 |
ref
會轉發到根元素。Slot 名稱 | 類別名稱 | 預設組件 | 描述 |
---|---|---|---|
area | AnimatedArea | 用於渲染區域的組件。 | |
axisContent | DefaultChartsAxisTooltipContent | 用於在座標軸事件觸發時顯示工具提示內容的自訂組件。 | |
bar | BarElementPath | 用於渲染長條的組件。 | |
itemContent | DefaultChartsItemTooltipContent | 用於在項目事件觸發時顯示工具提示內容的自訂組件。 | |
line | LineElementPath | 用於渲染折線的組件。 | |
lineHighlight | |||
mark | |||
popper | ChartsTooltipRoot | 用於工具提示 popper 的自訂組件。 |
原始碼
如果您在本頁中找不到資訊,請考慮查看組件的實作以取得更多詳細資訊。