# 介面:Defaults

# 階層

# 屬性

# animation

animation: false | AnimationSpec<keyof ChartTypeRegistry> & { onComplete?: (this: Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint)[], unknown>, event: AnimationEvent) => void ; onProgress?: (this: Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint)[], unknown>, event: AnimationEvent) => void }

# 繼承自

CoreChartOptions.animation

# 定義於

types/index.d.ts:1747 (開啟新視窗)


# animations

animations: AnimationsSpec<keyof ChartTypeRegistry>

# 繼承自

CoreChartOptions.animations

# 定義於

types/index.d.ts:1757 (開啟新視窗)


# aspectRatio

aspectRatio: number

畫布的長寬比 (即寬度 / 高度,值為 1 代表正方形畫布)。請注意,如果高度明確定義為屬性或透過樣式,則會忽略此選項。

預設值

2

# 繼承自

CoreChartOptions.aspectRatio

# 定義於

types/index.d.ts:1645 (開啟新視窗)


# backgroundColor

backgroundColor: Scriptable<Color, ScriptableContext<keyof ChartTypeRegistry>>

基礎背景顏色

請參閱

Defaults.backgroundColor

# 繼承自

CoreChartOptions.backgroundColor

# 定義於

types/index.d.ts:1614 (開啟新視窗)


# borderColor

borderColor: Scriptable<Color, ScriptableContext<keyof ChartTypeRegistry>>

基礎邊框顏色

請參閱

Defaults.borderColor

# 繼承自

CoreChartOptions.borderColor

# 定義於

types/index.d.ts:1619 (開啟新視窗)


# clip

clip: number | false | ChartArea

如何相對於 chartArea 進行裁剪。正值允許溢位,負值將在 chartArea 內部裁剪這麼多的像素。0 = 在 chartArea 裁剪。也可以針對每一邊設定裁剪: clip: {left: 5, top: false, right: -2, bottom: 0}

# 繼承自

CoreChartOptions.clip

# 定義於

types/index.d.ts:1603 (開啟新視窗)


# color

colorScriptable<Color, ScriptableContext<keyof ChartTypeRegistry>>

基礎顏色

請參閱

Defaults.color

# 繼承自

CoreChartOptions.color

# 定義於

types/index.d.ts:1609 (opens new window)


# datasets

datasetsObject

# 型別宣告

名稱 型別
bar BarControllerDatasetOptions
bubble BubbleControllerDatasetOptions
doughnut DoughnutControllerDatasetOptions
line LineControllerDatasetOptions & FillerControllerDatasetOptions
pie DoughnutControllerDatasetOptions
polarArea PolarAreaControllerDatasetOptions
radar RadarControllerDatasetOptions & FillerControllerDatasetOptions
scatter LineControllerDatasetOptions

# 繼承自

CoreChartOptions.datasets

# 定義於

types/index.d.ts:1590 (opens new window)


# devicePixelRatio

devicePixelRationumber

覆寫視窗預設的 devicePixelRatio。

預設值

window.devicePixelRatio

# 繼承自

CoreChartOptions.devicePixelRatio

# 定義於

types/index.d.ts:1662 (opens new window)


# elements

elementsElementOptionsByType<keyof ChartTypeRegistry>

# 繼承自

ElementChartOptions.elements

# 定義於

types/index.d.ts:2137 (opens new window)


# events

events:keyof HTMLElementEventMap[]

events 選項定義了圖表應監聽哪些瀏覽器事件,以顯示工具提示和懸停效果。

預設值

['mousemove', 'mouseout', 'click', 'touchstart', 'touchmove']

# 繼承自

CoreChartOptions.events

# 定義於

types/index.d.ts:1672 (opens new window)


# font

fontPartial<FontSpec>

基礎字型

請參閱

Defaults.font

# 繼承自

CoreChartOptions.font

# 定義於

types/index.d.ts:1624 (opens new window)


# hover

hoverCoreInteractionOptions

# 繼承自

CoreChartOptions.hover

# 定義於

types/index.d.ts:1666 (opens new window)


# indexAxis

indexAxis"x" | "y"

圖表的基礎軸。「x」表示垂直圖表,「y」表示水平圖表。

預設值

'x'

# 繼承自

CoreChartOptions.indexAxis

# 定義於

types/index.d.ts:1598 (opens new window)


# interaction

interactionCoreInteractionOptions

# 繼承自

CoreChartOptions.interaction

# 定義於

types/index.d.ts:1664 (opens new window)


# layout

layoutPartial<{ autoPaddingboolean ; paddingScriptable<Padding, ScriptableContext<keyof ChartTypeRegistry>> }>

# 繼承自

CoreChartOptions.layout

# 定義於

types/index.d.ts:1684 (opens new window)


# locale

localestring

用於數字格式化的地區設定(使用 Intl.NumberFormat)。

預設值

使用者瀏覽器設定

# 繼承自

CoreChartOptions.locale

# 定義於

types/index.d.ts:1651 (opens new window)


# maintainAspectRatio

maintainAspectRatioboolean

調整大小時,維持原始畫布的長寬比(寬度 / 高度)。若要讓此選項正常運作,圖表必須位於其專屬的容器中。

預設值

true

# 繼承自

CoreChartOptions.maintainAspectRatio

# 定義於

types/index.d.ts:1634 (opens new window)


# normalized

normalizedboolean

如果您提供的資料的索引是唯一的、已排序的,且在資料集中一致,並且提供 normalized: true 選項以告知 Chart.js 您已這麼做,則 Chart.js 的速度最快。

# 繼承自

CoreChartOptions.normalized

# 定義於

types/index.d.ts:63 (開啟新視窗)


# parsing (解析)

parsing: false | { [key: string]: string; }

如何解析資料集。可以透過在圖表選項或資料集中指定 `parsing: false` 來停用解析。如果停用解析,資料必須經過排序,並且採用關聯圖表類型和縮放比例內部使用的格式。

# 繼承自

CoreChartOptions.parsing

# 定義於

types/index.d.ts:54 (開啟新視窗)


# plugins (外掛)

plugins: PluginOptionsByType<keyof ChartTypeRegistry>

# 繼承自

PluginChartOptions.plugins

# 定義於

types/index.d.ts:2950 (開啟新視窗)


# resizeDelay (調整大小延遲)

resizeDelay: number

將調整大小的更新延遲指定的毫秒數。這可以透過對元素的更新進行防抖 (debouncing) 來簡化調整大小的過程。

預設值

0

# 繼承自

CoreChartOptions.resizeDelay

# 定義於

types/index.d.ts:1639 (開啟新視窗)


# responsive (響應式)

responsive: boolean

在其容器調整大小時調整圖表畫布的大小(重要提示...)。

預設值

true

# 繼承自

CoreChartOptions.responsive

# 定義於

types/index.d.ts:1629 (開啟新視窗)


# scale (比例尺)

scale: ScaleOptionsByType<keyof ScaleTypeRegistry>

# 定義於

types/index.d.ts:668 (開啟新視窗)


# scales (比例尺)

scales: Object

# 類型宣告

名稱 型別
category (類別) { type: "category" } & Omit<CartesianScaleOptions, "max" | "min"> & { labels: string[] | string[][] ; max: string | number ; min: string | number }
linear (線性) { type: "linear" } & CartesianScaleOptions & { beginAtZero: boolean ; grace?: string | number ; suggestedMax?: number ; suggestedMin?: number ; ticks: { count: number ; format: NumberFormatOptions ; precision: number ; stepSize: number } }
logarithmic (對數) { type: "logarithmic" } & CartesianScaleOptions & { suggestedMax?: number ; suggestedMin?: number ; ticks: { format: NumberFormatOptions } }
radialLinear (徑向線性) { type: "radialLinear" } & CoreScaleOptions & { angleLines: { borderDash: Scriptable<number[], ScriptableScaleContext> ; borderDashOffset: Scriptable<number, ScriptableScaleContext> ; color: Scriptable<Color, ScriptableScaleContext> ; display: boolean ; lineWidth: Scriptable<number, ScriptableScaleContext> } ; animate: boolean ; beginAtZero: boolean ; grid: Partial<GridLineOptions> ; max: number ; min: number ; pointLabels: { backdropColor: Scriptable<Color, ScriptableScalePointLabelContext> ; backdropPadding: Scriptable<number | ChartArea, ScriptableScalePointLabelContext> ; borderRadius: Scriptable<number | BorderRadius, ScriptableScalePointLabelContext> ; callback: (label: string, index: number) => string | number | string[] | number[] ; centerPointLabels: boolean ; color: Scriptable<Color, ScriptableScalePointLabelContext> ; display: boolean | "auto" ; font: ScriptableAndScriptableOptions<Partial<FontSpec>, ScriptableScalePointLabelContext> ; padding: Scriptable<number, ScriptableScalePointLabelContext> } ; startAngle: number ; suggestedMax: number ; suggestedMin: number ; ticks: RadialTickOptions }
time (時間) { type: "time" } & Omit<CartesianScaleOptions, "max" | "min"> & { adapters: { date: unknown } ; bounds: "data" | "ticks" ; max: string | number ; min: string | number ; offsetAfterAutoskip: boolean ; suggestedMax: string | number ; suggestedMin: string | number ; ticks: TimeScaleTickOptions ; time: TimeScaleTimeOptions }
timeseries (時間序列) { type: "timeseries" } & Omit<CartesianScaleOptions, "max" | "min"> & { adapters: { date: unknown } ; bounds: "data" | "ticks" ; max: string | number ; min: string | number ; offsetAfterAutoskip: boolean ; suggestedMax: string | number ; suggestedMin: string | number ; ticks: TimeScaleTickOptions ; time: TimeScaleTimeOptions }

# 定義於

types/index.d.ts:669 (開啟新視窗)


# transitions (過場效果)

transitions: TransitionsSpec<keyof ChartTypeRegistry>

# 繼承自

CoreChartOptions.transitions

# 定義於

types/index.d.ts:1758 (開啟新視窗)

# 方法

# describe (描述)

describe(scope, values): AnyObject

# 參數

名稱 型別
scope (範圍) string
values (值) AnyObject

# 返回

AnyObject

# 定義於

types/index.d.ts:677 (開啟新視窗)


# get (取得)

get(scope): AnyObject

# 參數

名稱 型別
scope (範圍) string

# 返回

AnyObject

# 定義於

types/index.d.ts:675 (開啟新視窗)


# onClick

onClick(event, elements, chart): void

當事件類型為 'mouseup' 或 'click' 時呼叫。傳入事件、活動元素的陣列以及圖表。

# 參數

名稱 型別
event ChartEvent
elements ActiveElement[]
chart Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint)[], unknown>

# 返回值

void

# 繼承自

CoreChartOptions.onClick

# 定義於

types/index.d.ts:1682 (開啟新視窗)


# onHover

onHover(event, elements, chart): void

當任何事件觸發時呼叫。傳入事件、活動元素(長條圖、點等)的陣列以及圖表。

# 參數

名稱 型別
event ChartEvent
elements ActiveElement[]
chart Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint)[], unknown>

# 返回值

void

# 繼承自

CoreChartOptions.onHover

# 定義於

types/index.d.ts:1677 (開啟新視窗)


# onResize

onResize(chart, size): void

當發生調整大小時呼叫。傳入兩個參數:圖表實例和新的尺寸。

# 參數

名稱 型別
chart Chart<keyof ChartTypeRegistry, (number | [number, number] | Point | BubbleDataPoint)[], unknown>
size 物件
size.height number
size.width number

# 返回值

void

# 繼承自

CoreChartOptions.onResize

# 定義於

types/index.d.ts:1656 (開啟新視窗)


# override

override(scope, values): AnyObject

# 參數

名稱 型別
scope (範圍) string
values (值) AnyObject

# 返回值

AnyObject

# 定義於

types/index.d.ts:678 (開啟新視窗)


# route

route(scope, name, targetScope, targetName): void

將具名預設值路由至另一個範圍/名稱的後備。當那些目標值(例如 defaults.color)在執行時變更時,此路由很有用。如果複製值,則執行時的變更將不會生效。透過路由,會在每次存取時評估後備,因此它始終是最新的。

範例

defaults.route('elements.arc', 'backgroundColor', '', 'color')

  • 當本地未定義時,從 defaults.color 讀取 backgroundColor

# 參數

名稱 型別 說明
scope (範圍) string 此路由套用的範圍。
name string 當此處未定義時,應路由到不同命名空間的屬性名稱。
targetScope string 應將這些屬性路由到的命名空間。空字串 ('') 是預設值的根目錄。
targetName string 屬性應路由到的目標範圍中的目標名稱。

# 返回值

void

# 定義於

types/index.d.ts:697 (開啟新視窗)


# set

set(values): AnyObject

# 參數

名稱 型別
values (值) AnyObject

# 返回值

AnyObject

# 定義於

types/index.d.ts:673 (開啟新視窗)

set(scope, values): AnyObject

# 參數

名稱 型別
scope (範圍) string
values (值) AnyObject

# 返回值

AnyObject

# 定義於

types/index.d.ts:674 (開啟新視窗)