通道选项#

一些编码通道允许表达额外的选项。这些选项可以控制诸如轴属性、比例尺属性、头部和标题、分箱参数、聚合、排序等等。

下面的章节标题指的是在通道中介绍的通道,并显示了这些通道可接受的选项。

X 和 Y#

XY 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

axis

anyOf(Axis, null)

一个对象,定义了轴的网格线、刻度和标签的属性。如果为 null,则会移除编码通道的轴。

默认值: 如果未定义,将应用默认的 轴属性 <https://vega.github.io/vega-lite/docs/axis.html>__。

另请参见: axis <https://vega.github.io/vega-lite/docs/axis.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, string, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

impute

anyOf(ImputeParams, null)

一个对象,定义要应用的插补操作的属性。另一个位置通道的字段值被用作插补操作的 key。如果指定了 color 通道的字段,则将其用作插补操作的 groupby

另请参见: impute <https://vega.github.io/vega-lite/docs/impute.html>__ 文档。

scale

anyOf(Scale, null)

一个对象,定义通道比例尺的属性,比例尺是将数据域(数字、日期、字符串等)中的值转换为编码通道视觉值(像素、颜色、大小)的函数。

如果为 null,则比例尺将被禁用,并且数据值将直接编码 <https://vega.github.io/vega-lite/docs/scale.html#disable>__。

默认值: 如果未定义,将应用默认的 比例尺属性 <https://vega.github.io/vega-lite/docs/scale.html>__。

另请参见: scale <https://vega.github.io/vega-lite/docs/scale.html>__ 文档。

sort

排序

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个字符串,指示用于排序的编码通道名称 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__(例如,"x""y"),可选添加负号前缀表示降序(例如,"-x" 表示按 x 字段降序排序)。此通道字符串是 sort-by-encoding 定义的缩写形式 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__。例如,"sort": "-x" 等同于 "sort": {"encoding": "x", "order": "descending"}

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null 和按另一个通道排序。

另请参见: sort <https://vega.github.io/vega-lite/docs/sort.html>__ 文档。

stack

anyOf(StackOffset, null, boolean)

如果字段需要堆叠,则指定堆叠偏移的类型。stack 仅适用于具有连续域的 x, y, thetaradius 通道。例如,ystack 可用于定制垂直条形图的堆叠。

stack 可以是以下值之一

  • "zero"true:以比例尺的零值作为基线进行堆叠(用于创建典型的堆叠条形图 <https://vega.github.io/vega-lite/docs/stack.html#bar>__ 和面积图 <https://vega.github.io/vega-lite/docs/stack.html#area>__)。

  • "normalize" - 使用标准化域进行堆叠(用于创建标准化堆叠条形图和面积图 <https://vega.github.io/vega-lite/docs/stack.html#normalized>__ 和带百分比提示的饼图 <https://vega.github.io/vega-lite/docs/arc.html#tooltip>**)。 -"center" - 使用中心基线进行堆叠(用于流图 <https://vega.github.io/vega-lite/docs/stack.html#streamgraph>**)。

  • nullfalse - 不堆叠。这将生成分层条形图 <https://vega.github.io/vega-lite/docs/stack.html#layered-bar-chart>__ 和面积图。

默认值: 对于满足以下所有条件的图表,默认值为 zero:(1) 标记是 barareaarc;(2) 堆叠度量通道(x 或 y)具有线性比例尺;(3) 至少有一个非位置通道映射到未聚合的字段,且该字段与 x 和 y 不同。否则,默认值为 null

另请参见: stack <https://vega.github.io/vega-lite/docs/stack.html>__ 文档。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

颜色、填充和描边#

ColorFillStroke 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

condition

anyOf(ConditionalValueDef<(Gradient|string|null|ExprRef)>, array(ConditionalValueDef<(Gradient|string|null|ExprRef)>))

一个或多个值定义,带有参数或测试谓词 <https://vega.github.io/vega-lite/docs/condition.html>__。

注意: 字段定义的 condition 属性只能包含条件值定义 <https://vega.github.io/vega-lite/docs/condition.html#value>__,因为 Vega-Lite 每个编码通道最多只允许一个编码字段。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

legend

anyOf(Legend, null)

一个对象,定义图例的属性。如果为 null,则会移除编码通道的图例。

默认值: 如果未定义,将应用默认的 图例属性 <https://vega.github.io/vega-lite/docs/legend.html>__。

另请参见: legend <https://vega.github.io/vega-lite/docs/legend.html>__ 文档。

scale

anyOf(Scale, null)

一个对象,定义通道比例尺的属性,比例尺是将数据域(数字、日期、字符串等)中的值转换为编码通道视觉值(像素、颜色、大小)的函数。

如果为 null,则比例尺将被禁用,并且数据值将直接编码 <https://vega.github.io/vega-lite/docs/scale.html#disable>__。

默认值: 如果未定义,将应用默认的 比例尺属性 <https://vega.github.io/vega-lite/docs/scale.html>__。

另请参见: scale <https://vega.github.io/vega-lite/docs/scale.html>__ 文档。

sort

排序

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个字符串,指示用于排序的编码通道名称 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__(例如,"x""y"),可选添加负号前缀表示降序(例如,"-x" 表示按 x 字段降序排序)。此通道字符串是 sort-by-encoding 定义的缩写形式 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__。例如,"sort": "-x" 等同于 "sort": {"encoding": "x", "order": "descending"}

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null 和按另一个通道排序。

另请参见: sort <https://vega.github.io/vega-lite/docs/sort.html>__ 文档。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

形状#

Shape 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

condition

anyOf(ConditionalValueDef<(string|null|ExprRef)>, array(ConditionalValueDef<(string|null|ExprRef)>))

一个或多个值定义,带有参数或测试谓词 <https://vega.github.io/vega-lite/docs/condition.html>__。

注意: 字段定义的 condition 属性只能包含条件值定义 <https://vega.github.io/vega-lite/docs/condition.html#value>__,因为 Vega-Lite 每个编码通道最多只允许一个编码字段。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

legend

anyOf(Legend, null)

一个对象,定义图例的属性。如果为 null,则会移除编码通道的图例。

默认值: 如果未定义,将应用默认的 图例属性 <https://vega.github.io/vega-lite/docs/legend.html>__。

另请参见: legend <https://vega.github.io/vega-lite/docs/legend.html>__ 文档。

scale

anyOf(Scale, null)

一个对象,定义通道比例尺的属性,比例尺是将数据域(数字、日期、字符串等)中的值转换为编码通道视觉值(像素、颜色、大小)的函数。

如果为 null,则比例尺将被禁用,并且数据值将直接编码 <https://vega.github.io/vega-lite/docs/scale.html#disable>__。

默认值: 如果未定义,将应用默认的 比例尺属性 <https://vega.github.io/vega-lite/docs/scale.html>__。

另请参见: scale <https://vega.github.io/vega-lite/docs/scale.html>__ 文档。

sort

排序

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个字符串,指示用于排序的编码通道名称 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__(例如,"x""y"),可选添加负号前缀表示降序(例如,"-x" 表示按 x 字段降序排序)。此通道字符串是 sort-by-encoding 定义的缩写形式 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__。例如,"sort": "-x" 等同于 "sort": {"encoding": "x", "order": "descending"}

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null 和按另一个通道排序。

另请参见: sort <https://vega.github.io/vega-lite/docs/sort.html>__ 文档。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

TypeForShape

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

顺序#

Order 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, string, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

sort

SortOrder

排序顺序。可以是 "ascending"(升序,默认)或 "descending"(降序)之一。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

角度、填充不透明度、不透明度、大小、描边不透明度和描边宽度#

AngleFillOpacityOpacitySizeStrokeOpacityStrokeWidth 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

condition

anyOf(ConditionalValueDef<(number|ExprRef)>, array(ConditionalValueDef<(number|ExprRef)>))

一个或多个值定义,带有参数或测试谓词 <https://vega.github.io/vega-lite/docs/condition.html>__。

注意: 字段定义的 condition 属性只能包含条件值定义 <https://vega.github.io/vega-lite/docs/condition.html#value>__,因为 Vega-Lite 每个编码通道最多只允许一个编码字段。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

legend

anyOf(Legend, null)

一个对象,定义图例的属性。如果为 null,则会移除编码通道的图例。

默认值: 如果未定义,将应用默认的 图例属性 <https://vega.github.io/vega-lite/docs/legend.html>__。

另请参见: legend <https://vega.github.io/vega-lite/docs/legend.html>__ 文档。

scale

anyOf(Scale, null)

一个对象,定义通道比例尺的属性,比例尺是将数据域(数字、日期、字符串等)中的值转换为编码通道视觉值(像素、颜色、大小)的函数。

如果为 null,则比例尺将被禁用,并且数据值将直接编码 <https://vega.github.io/vega-lite/docs/scale.html#disable>__。

默认值: 如果未定义,将应用默认的 比例尺属性 <https://vega.github.io/vega-lite/docs/scale.html>__。

另请参见: scale <https://vega.github.io/vega-lite/docs/scale.html>__ 文档。

sort

排序

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个字符串,指示用于排序的编码通道名称 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__(例如,"x""y"),可选添加负号前缀表示降序(例如,"-x" 表示按 x 字段降序排序)。此通道字符串是 sort-by-encoding 定义的缩写形式 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__。例如,"sort": "-x" 等同于 "sort": {"encoding": "x", "order": "descending"}

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null 和按另一个通道排序。

另请参见: sort <https://vega.github.io/vega-lite/docs/sort.html>__ 文档。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

虚线样式#

StrokeDash 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

condition

anyOf(ConditionalValueDef<(number[]|ExprRef)>, array(ConditionalValueDef<(number[]|ExprRef)>))

一个或多个值定义,带有参数或测试谓词 <https://vega.github.io/vega-lite/docs/condition.html>__。

注意: 字段定义的 condition 属性只能包含条件值定义 <https://vega.github.io/vega-lite/docs/condition.html#value>__,因为 Vega-Lite 每个编码通道最多只允许一个编码字段。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

legend

anyOf(Legend, null)

一个对象,定义图例的属性。如果为 null,则会移除编码通道的图例。

默认值: 如果未定义,将应用默认的 图例属性 <https://vega.github.io/vega-lite/docs/legend.html>__。

另请参见: legend <https://vega.github.io/vega-lite/docs/legend.html>__ 文档。

scale

anyOf(Scale, null)

一个对象,定义通道比例尺的属性,比例尺是将数据域(数字、日期、字符串等)中的值转换为编码通道视觉值(像素、颜色、大小)的函数。

如果为 null,则比例尺将被禁用,并且数据值将直接编码 <https://vega.github.io/vega-lite/docs/scale.html#disable>__。

默认值: 如果未定义,将应用默认的 比例尺属性 <https://vega.github.io/vega-lite/docs/scale.html>__。

另请参见: scale <https://vega.github.io/vega-lite/docs/scale.html>__ 文档。

sort

排序

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个字符串,指示用于排序的编码通道名称 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__(例如,"x""y"),可选添加负号前缀表示降序(例如,"-x" 表示按 x 字段降序排序)。此通道字符串是 sort-by-encoding 定义的缩写形式 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__。例如,"sort": "-x" 等同于 "sort": {"encoding": "x", "order": "descending"}

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null 和按另一个通道排序。

另请参见: sort <https://vega.github.io/vega-lite/docs/sort.html>__ 文档。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

行和列#

RowColumnFacet 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

align

LayoutAlign

应用于行/列分面子图的对齐方式。支持的字符串值包括 "all""each""none"

  • 如果设置为 "none",将使用流式布局,其中相邻的子视图只是一个接一个地放置。

  • 如果设置为 "each",子视图将对齐形成整洁的网格结构,但每行或每列的大小可能不同。

  • 如果设置为 "all",子视图将对齐,且每行或每列的大小将基于观察到的最大尺寸完全相同。此属性的字符串值将应用于网格的行和列。

默认值: "all"

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

center

boolean

布尔标志,指示分面的子视图是否应相对于其各自的行或列居中对齐。

默认值: false

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

header

anyOf(Header, null)

一个对象,定义分面头部的属性。

sort

anyOf(SortArray, SortOrder, EncodingSortField, null)

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null

spacing

number

分面子视图之间的像素间距。

默认值:取决于视图组合配置 <https://vega.github.io/vega-lite/docs/config.html#view-config>__ 的 "spacing" 属性(默认为 20

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

分面#

Facet 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

align

anyOf(LayoutAlign, RowCol<LayoutAlign>)

应用于网格行和列的对齐方式。支持的字符串值包括 "all""each""none"

  • 如果设置为 "none",将使用流式布局,其中相邻的子视图只是一个接一个地放置。

  • 如果设置为 "each",子视图将对齐形成整洁的网格结构,但每行或每列的大小可能不同。

  • 如果设置为 "all",子视图将对齐,且每行或每列的大小将基于观察到的最大尺寸完全相同。此属性的字符串值将应用于网格的行和列。

或者,可以使用 {"row": string, "column": string} 形式的对象值来为行和列提供不同的对齐方式。

默认值: "all"

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

bounds

[‘full’, ‘flush’]

用于确定子图范围的边界计算方法。可以是 full(默认)或 flush 之一。

  • 如果设置为 full,将使用整个计算出的边界(包括轴、标题和图例)。

  • 如果设置为 flush,则仅使用为子视图指定的宽度和高度值。flush 设置在尝试将不带轴或图例的子图放置到统一网格结构中时很有用。

默认值: "full"

center

anyOf(boolean, RowCol<boolean>)

布尔标志,指示子视图是否应相对于其各自的行或列居中对齐。

可以使用 {"row": boolean, "column": boolean} 形式的对象值来为行和列提供不同的居中值。

默认值: false

columns

number

视图组合布局中包含的列数。

默认值undefined – 将假定无限数量的列(单行)。这等同于 hconcat(用于 concat)以及使用 column 通道(用于 facetrepeat)。

注意:

  1. 此属性仅适用于

  • 通用的(可换行的)concat 操作符(非 hconcat/vconcat

  • 带有单个字段/重复定义的 facetrepeat 操作符(不含行/列嵌套)

  1. columns 设置为 1 等同于 vconcat(用于 concat 马可)以及使用 row 通道(用于 facetrepeat)。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

header

anyOf(Header, null)

一个对象,定义分面头部的属性。

sort

anyOf(SortArray, SortOrder, EncodingSortField, null)

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null

spacing

anyOf(number, RowCol<number>)

组合操作符的子视图之间的像素间距。可以使用 {"row": number, "column": number} 形式的对象来为行和列设置不同的间距值。

默认值:取决于视图组合配置 <https://vega.github.io/vega-lite/docs/config.html#view-config>__ 的 "spacing" 属性(默认为 20

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

文本#

Text 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, string, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

condition

anyOf(ConditionalValueDef<(Text|ExprRef)>, array(ConditionalValueDef<(Text|ExprRef)>))

一个或多个值定义,带有参数或测试谓词 <https://vega.github.io/vega-lite/docs/condition.html>__。

注意: 字段定义的 condition 属性只能包含条件值定义 <https://vega.github.io/vega-lite/docs/condition.html#value>__,因为 Vega-Lite 每个编码通道最多只允许一个编码字段。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

format

anyOf(string, Dict)

与默认的 "number"(数字)和 "time"(时间)格式类型一起使用时,用于指南(轴、图例、头部)和文本标记标签的文本格式模式。

  • 如果格式类型是 "number"(例如,定量字段),这是 D3 的 数字格式模式 <https://github.com/d3/d3-format#locale_format>__。

  • 如果格式类型是 "time"(例如,时间字段),这是 D3 的 时间格式模式 <https://github.com/d3/d3-time-format#locale_format>__。

更多示例请参阅 format 文档 <https://vega.github.io/vega-lite/docs/format.html>__。

自定义 formatType <https://vega.github.io/vega-lite/docs/config.html#custom-format-type>__ 一起使用时,此值将作为 formatdatum.value 一起传递给注册的函数。

默认值: 数字格式从 numberFormat <https://vega.github.io/vega-lite/docs/config.html#format>__ 配置派生,时间格式从 timeFormat <https://vega.github.io/vega-lite/docs/config.html#format>__ 配置派生。

formatType

string

标签的格式类型。可以是 "number""time"已注册的自定义格式类型 <https://vega.github.io/vega-lite/docs/config.html#custom-format-type>__ 之一。

默认值

  • 时间字段以及带有 timeUnit 的序数和名义字段,使用 "time"

  • 定量字段以及不带 timeUnit 的序数和名义字段,使用 "number"

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

超链接、工具提示、URL#

HrefTooltipUrl 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, string, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

condition

anyOf(ConditionalValueDef<(string|ExprRef)>, array(ConditionalValueDef<(string|ExprRef)>))

一个或多个值定义,带有参数或测试谓词 <https://vega.github.io/vega-lite/docs/condition.html>__。

注意: 字段定义的 condition 属性只能包含条件值定义 <https://vega.github.io/vega-lite/docs/condition.html#value>__,因为 Vega-Lite 每个编码通道最多只允许一个编码字段。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

format

anyOf(string, Dict)

与默认的 "number"(数字)和 "time"(时间)格式类型一起使用时,用于指南(轴、图例、头部)和文本标记标签的文本格式模式。

  • 如果格式类型是 "number"(例如,定量字段),这是 D3 的 数字格式模式 <https://github.com/d3/d3-format#locale_format>__。

  • 如果格式类型是 "time"(例如,时间字段),这是 D3 的 时间格式模式 <https://github.com/d3/d3-time-format#locale_format>__。

更多示例请参阅 format 文档 <https://vega.github.io/vega-lite/docs/format.html>__。

自定义 formatType <https://vega.github.io/vega-lite/docs/config.html#custom-format-type>__ 一起使用时,此值将作为 formatdatum.value 一起传递给注册的函数。

默认值: 数字格式从 numberFormat <https://vega.github.io/vega-lite/docs/config.html#format>__ 配置派生,时间格式从 timeFormat <https://vega.github.io/vega-lite/docs/config.html#format>__ 配置派生。

formatType

string

标签的格式类型。可以是 "number""time"已注册的自定义格式类型 <https://vega.github.io/vega-lite/docs/config.html#custom-format-type>__ 之一。

默认值

  • 时间字段以及带有 timeUnit 的序数和名义字段,使用 "time"

  • 定量字段以及不带 timeUnit 的序数和名义字段,使用 "number"

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

细节#

Detail 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, string, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

纬度和经度#

LatitudeLongitude 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

null

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

string

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

半径和角度#

RadiusTheta 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

anyOf(boolean, BinParams, string, null)

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

scale

anyOf(Scale, null)

一个对象,定义通道比例尺的属性,比例尺是将数据域(数字、日期、字符串等)中的值转换为编码通道视觉值(像素、颜色、大小)的函数。

如果为 null,则比例尺将被禁用,并且数据值将直接编码 <https://vega.github.io/vega-lite/docs/scale.html#disable>__。

默认值: 如果未定义,将应用默认的 比例尺属性 <https://vega.github.io/vega-lite/docs/scale.html>__。

另请参见: scale <https://vega.github.io/vega-lite/docs/scale.html>__ 文档。

sort

排序

编码字段的排序顺序。

对于连续字段(定量或时间),sort 可以是 "ascending"(升序)或 "descending"(降序)。

对于离散字段,sort 可以是以下之一

  • "ascending""descending" – 根据值在 JavaScript 中的自然顺序排序。

  • 一个字符串,指示用于排序的编码通道名称 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__(例如,"x""y"),可选添加负号前缀表示降序(例如,"-x" 表示按 x 字段降序排序)。此通道字符串是 sort-by-encoding 定义的缩写形式 <https://vega.github.io/vega-lite/docs/sort.html#sort-by-encoding>__。例如,"sort": "-x" 等同于 "sort": {"encoding": "x", "order": "descending"}

  • 一个排序字段定义 <https://vega.github.io/vega-lite/docs/sort.html#sort-field>__,用于按另一个字段排序。

  • 一个数组,指定字段值的首选顺序 <https://vega.github.io/vega-lite/docs/sort.html#sort-array>__。在这种情况下,排序顺序将遵循数组中的值,然后是任何未指定值的原始顺序。对于离散时间字段,排序数组中的值可以是 日期时间定义对象 <https://vega.github.io/vega-lite/docs/datetime.html>__。此外,对于时间单位 "month""day",值可以是月份或日期的名称(不区分大小写)或其 3 个字母的缩写(例如,"Mon", "Tue")。

  • null 表示不排序。

默认值: "ascending"

注意: rowcolumn 不支持 null 和按另一个通道排序。

另请参见: sort <https://vega.github.io/vega-lite/docs/sort.html>__ 文档。

stack

anyOf(StackOffset, null, boolean)

如果字段需要堆叠,则指定堆叠偏移的类型。stack 仅适用于具有连续域的 x, y, thetaradius 通道。例如,ystack 可用于定制垂直条形图的堆叠。

stack 可以是以下值之一

  • "zero"true:以比例尺的零值作为基线进行堆叠(用于创建典型的堆叠条形图 <https://vega.github.io/vega-lite/docs/stack.html#bar>__ 和面积图 <https://vega.github.io/vega-lite/docs/stack.html#area>__)。

  • "normalize" - 使用标准化域进行堆叠(用于创建标准化堆叠条形图和面积图 <https://vega.github.io/vega-lite/docs/stack.html#normalized>__ 和带百分比提示的饼图 <https://vega.github.io/vega-lite/docs/arc.html#tooltip>**)。 -"center" - 使用中心基线进行堆叠(用于流图 <https://vega.github.io/vega-lite/docs/stack.html#streamgraph>**)。

  • nullfalse - 不堆叠。这将生成分层条形图 <https://vega.github.io/vega-lite/docs/stack.html#layered-bar-chart>__ 和面积图。

默认值: 对于满足以下所有条件的图表,默认值为 zero:(1) 标记是 barareaarc;(2) 堆叠度量通道(x 或 y)具有线性比例尺;(3) 至少有一个非位置通道映射到未聚合的字段,且该字段与 x 和 y 不同。否则,默认值为 null

另请参见: stack <https://vega.github.io/vega-lite/docs/stack.html>__ 文档。

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。

type

StandardType

编码字段或常量值(datum)的测量类型("quantitative"(定量), "temporal"(时间), "ordinal"(序数), 或 "nominal"(名义))。它也可以是 "geojson" 类型,用于编码 '地理形状' <https://vega.github.io/vega-lite/docs/geoshape.html>__。

Vega-Lite 在许多情况下会自动推断数据类型,如下所述。但是,如果满足以下条件,则字段需要指定类型:(1) 字段不是名义类型,且字段编码没有指定 aggregateargminargmax 除外)、bin、比例尺类型、自定义 sort 顺序或 timeUnit;或者 (2) 你希望对带有 bintimeUnit 的字段使用序数比例尺。

默认值

  1. 对于数据 field,默认数据类型是 "nominal",除非字段编码具有满足以下条件的 aggregatechannelbin、比例尺类型、sorttimeUnit

  • "quantitative" 是默认类型,如果 (1) 编码字段包含 binaggregate"argmin""argmax" 除外),(2) 编码通道是 latitudelongitude 通道,或者 (3) 如果指定的比例尺类型是定量比例尺 <https://vega.github.io/vega-lite/docs/scale.html#type>__。

  • "temporal" 是默认类型,如果 (1) 编码字段包含 timeUnit,或者 (2) 指定的比例尺类型是时间或 utc 比例尺

  • "ordinal" 是默认类型,如果 (1) 编码字段包含自定义排序顺序 <https://vega.github.io/vega-lite/docs/sort.html#specifying-custom-sort-order>__,(2) 指定的比例尺类型是序数/点/条带比例尺,或者 (3) 编码通道是 order

  1. 对于数据域中的常量值(datum

  • 如果 datum 是数字,则为 "quantitative"

  • 如果 datum 是字符串,则为 "nominal"

  • 如果 datum 是日期时间对象 <https://vega.github.io/vega-lite/docs/datetime.html>__,则为 "temporal"

注意

  • 数据 type 描述的是数据的语义,而不是基本数据类型(数字、字符串等)。相同的基础数据类型可以有不同的测量类型。例如,数值数据可以表示定量、序数或名义数据。

  • 时间字段的数据值可以是日期时间字符串(例如,"2015-03-07 12:32:17", "17:01", "2015-03-16", "2015")或时间戳数字(例如,1552199579097)。

  • bin <https://vega.github.io/vega-lite/docs/bin.html>__ 一起使用时,type 属性可以是 "quantitative"(用于线性分箱比例尺)或 "ordinal" (用于序数分箱比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 一起使用时,type 属性可以是 "temporal"(默认,用于时间比例尺)或 "ordinal" (用于序数比例尺) <https://vega.github.io/vega-lite/docs/type.html#cast-bin>__。

  • aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 一起使用时,type 属性指的是聚合后的数据类型。例如,我们可以使用 {"aggregate": "distinct", "field": "cat"} 计算分类字段 "cat" 的不同值计数。聚合输出的 "type""quantitative"

  • 次要通道(例如,x2, y2, xError, yError)没有 type 属性,因为它们的类型必须与其主要通道(例如,x, y)完全相同。

另请参见: type <https://vega.github.io/vega-lite/docs/type.html>__ 文档。

Latitude2、Longitude2、Radius2、Theta2、X2、Y2、XError、YError、XError2 和 YError2#

Latitude2Longitude2Radius2Theta2X2Y2XErrorYErrorXError2YError2 编码接受以下选项

点击显示表格

属性

类型

描述

aggregate

聚合

字段的聚合函数(例如,"mean", "sum", "median", "min", "max", "count")。

默认值: undefined (None)

另请参见: aggregate <https://vega.github.io/vega-lite/docs/aggregate.html>__ 文档。

bandPosition

number

在堆叠、分箱、时间单位或条带比例尺的条带上的相对位置。例如,如果设置为 0,标记将位于条带的开始位置;如果设置为 0.5,标记将位于条带的中间位置。

bin

null

一个用于对 quantitative 字段进行分箱的标志,一个定义分箱参数的对象 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__,或者指示 xy 通道的数据在导入 Vega-Lite 之前已经被分箱("binned")。

  • 如果为 true,将应用默认的 分箱参数 <https://vega.github.io/vega-lite/docs/bin.html#bin-parameters>__。

  • 如果为 "binned",则表示 x(或 y)通道的数据已经被分箱。你可以将分箱起始字段映射到 x(或 y),将分箱结束字段映射到 x2(或 y2)。比例尺和轴的格式将类似于 Vega-Lite 中的分箱。要根据分箱步长调整轴刻度,你还可以设置轴的 tickMinStep <https://vega.github.io/vega-lite/docs/axis.html#ticks>__ 属性。

默认值: false

另请参见: bin <https://vega.github.io/vega-lite/docs/bin.html>__ 文档。

field

字段

必填。 定义从哪个字段中提取数据值的字符串,或一个定义从 repeat <https://vega.github.io/vega-lite/docs/repeat.html>__ 操作符中迭代获取值的对象。

另请参见: field <https://vega.github.io/vega-lite/docs/field.html>__ 文档。

注意: 1) 点 (.) 和方括号 ([]) 可用于访问嵌套对象(例如,"field": "foo.bar""field": "foo['bar']")。如果字段名包含点或方括号但不是嵌套的,可以使用 \\ 进行转义(例如,"a\\.b""a\\[0\\]")。更多关于转义的详细信息,请参见 field 文档 <https://vega.github.io/vega-lite/docs/field.html>__。2) 如果 aggregatecount,则不需要 field

timeUnit

anyOf(TimeUnit, BinnedTimeUnit, TimeUnitParams)

时间字段的时间单位(例如,year, yearmonth, month, hours),或被强制转换为序数的时间字段 <https://vega.github.io/vega-lite/docs/type.html#cast>__。

默认值: undefined (None)

另请参见: timeUnit <https://vega.github.io/vega-lite/docs/timeunit.html>__ 文档。

title

anyOf(Text, null)

字段的标题。如果为 null,则会移除标题。

默认值: 从字段名和转换函数(aggregatebintimeUnit)派生。如果字段有聚合函数,则该函数作为标题的一部分显示(例如,"Sum of Profit")。如果字段被分箱或应用了时间单位,则应用的函数会显示在括号中(例如,"Profit (binned)""Transaction Date (year-month)")。否则,标题就是简单的字段名。

注意:

  1. 你可以通过在 config <https://vega.github.io/vega-lite/docs/config.html>__ 中提供 fieldTitle <https://vega.github.io/vega-lite/docs/config.html#top-level-config>__ 属性或通过 compile 函数选项中的 fieldTitle 函数 <https://vega.github.io/vega-lite/usage/compile.html#field-title>__ 来自定义默认的字段标题格式。

  2. 如果同时定义了字段定义的 title 和轴、头部或图例的 title,则使用轴/头部/图例的标题。