本页面演示了如何在 dashboard.lkml 文件中使用 LookML 信息中心参数添加和自定义 type: looker_grid 的 LookML 信息中心元素。
如需了解如何通过 Looker 界面构建表格图表,请参阅表格图表选项文档页面。
用法示例
## BASIC PARAMETERS
name: element_name
title: 'Element Title'
type: looker_grid
height: N
width: N
top: N
left: N
row: N
col: N
refresh: N (seconds | minutes | hours | days)
note_state: collapsed | expanded
note_display: above | below | hover
note_text: 'note text'
## QUERY PARAMETERS
model: model_name
explore: explore_name
fields: [view_name.field_name, view_name.field_name, …]
dimensions: [view_name.field_name, view_name.field_name, …]
measures: [view_name.field_name, view_name.field_name, …]
sorts: [view_name.field_name asc | desc, view_name.field_name, …]
pivots: [view_name.field_name, view_name.field_name, …]
fill_fields: [view_name.field_name, view_name.field_name, …]
subtotals: [view_name.field_name, view_name.field_name, …]
total: true | false
row_total: right | left | false
limit: N
column_limit: N
filters:
view_name.field_name: 'Looker filter expression' | 'filter value'
filter_expression: 'Looker custom filter expression'
listen:
dashboard_filter_name: view_name.field_name
query_timezone: 'specific timezone' | user_timezone
analysis_config: # can only be used when the Forecasting Labs feature is enabled
forecasting:
- confidence_interval: N
field_name: view_name.field_name
forecast_n: N
forecast_interval: day | month | a time frame with dimension fill
seasonality: N
merged_queries:
- 'primary query definition'
- 'next source query definition'
join_fields:
- field_name: view_name.field_name
source_field_name: view_name.field_name
## COLUMN PARAMETERS
auto_size_all_columns: true | false
column_order: [view_name.field_name, view_name.field_name, …]
pinned_columns:
view_name.field_name: left
## PLOT PARAMETERS
table_theme: editable | white | gray | transparent | unstyled
show_row_numbers: true | false
hide_totals: true | false
hide_row_totals: true | false
transpose: true | false
hidden_fields: [view_name.field_name, view_name.field_name, …]
limit_displayed_rows: true | false
limit_displayed_rows_values:
show_hide: show | hide
first_last: first | last
num_rows: 'N'
## SERIES PARAMETERS
truncate_text: true | false
show_view_names: true | false
size_to_fit: true | false
dynamic_fields:
- table_calculation: {'table calculation definition'}
- measure: {'custom measure or custom filtered measure definition'}
- dimension: {'custom dimension definition'}
series_labels:
view_name.field_name: 'Series Label'
series_column_widths:
view_name.field_name: N
series_cell_visualizations:
view_name.field_name:
is_active: true | false
palette:
palette_id: 'palette ID'
collection_id: 'collection ID'
custom_colors:
- 'color value'
value_display: true | false
series_text_format:
view_name.field_name:
fg_color: 'color value'
bg_color: 'color value'
bold: true | false
italic: true | false
align: left | center | right
series_collapsed:
view_name.field_name: true | false
series_value_format:
view_name.field_name:
format_string: 'value formatting string'
## FORMATTING PARAMETERS
color_application:
collection_id: 'collection ID'
palette_id: 'palette ID'
header_font_color: 'color value'
header_background_color: 'color value'
header_text_alignment: left | center | right
header_font_size: N
rows_font_size: N
enable_conditional_formatting: true | false
conditional_formatting_include_totals: true | false
conditional_formatting_include_nulls: true | false
conditional_formatting:
{'desired conditional formatting'}
参数定义
| 参数名称 | 说明 | |
|---|---|---|
| 基本参数 | ||
name(适用于元素) |
创建元素 | |
title(适用于元素) |
更改元素名称向用户的显示方式 | |
type(适用于元素) |
确定要在元素中使用的可视化图表类型 | |
height(适用于元素) |
以 tile_size 为单位定义 layout: tile 和 layout: static 信息中心内元素的高度 |
|
width(适用于元素) |
以 tile_size 为单位定义 layout: tile 和 layout: static 信息中心内元素的宽度 |
|
top |
定义元素在 layout: static 信息中心内从上到下的位置,以 tile_size 为单位 |
|
left |
以 tile_size 为单位定义元素在 layout: static 信息中心内从左到右的位置 |
|
row |
定义 layout: newspaper 信息中心内元素从上到下的位置(以行为单位) |
|
col |
以列为单位定义 layout: newspaper 信息中心内元素的从左到右位置 |
|
refresh(适用于元素) |
设置元素自动刷新的间隔 | |
note_state |
定义当备注过大而无法在元素宽度内单行显示时,是折叠还是展开 | |
note_display |
定义备注在元素上的显示位置 | |
note_text |
指定备注中显示的文本 | |
| 查询参数 | ||
model |
定义要用于元素查询的模型 | |
explore(适用于元素) |
定义要用于元素查询的探索 | |
fields |
定义要用于元素查询的字段。这可以代替 dimensions 和 measures。 |
|
dimensions |
定义要用于元素查询的维度 | |
measures |
定义要用于元素查询的测量 | |
sorts |
定义要用于元素查询的排序 | |
pivots |
定义应透视以用于元素查询的维度 | |
fill_fields |
定义使用维度填充选项的维度 | |
subtotals |
定义要计算小计的字段 | |
total |
指定是否为可视化表显示列总计 | |
row_total |
指定是否为表格可视化图表显示行总计 | |
limit |
定义要用于元素查询的行数上限 | |
column_limit |
定义要用于元素查询的列数限制 | |
filters(适用于元素) |
定义无法为元素查询更改的过滤条件 | |
filter_expression |
定义无法为元素查询更改的自定义过滤条件 | |
listen |
定义可以为元素的查询更改的过滤条件(如果已创建 filters [针对信息中心]) |
|
query_timezone |
定义运行查询时应使用的时区 | |
analysis_config |
添加了 21.14 定义运行查询时应执行的预测分析。需要启用预测实验室功能。 | |
merged_queries |
定义合并结果查询 | |
| 列参数 | ||
auto_size_all_columns |
将每个表格列自动调整为列标题或最长数据值的宽度(以较宽者为准) | |
column_order |
对表格图表中的列进行排序 | |
pinned_columns |
定义要在表格图表左侧固定或冻结的列 | |
| 绘图参数 | ||
table_theme |
将五种表格着色选项之一应用于表格可视化图表 | |
show_row_numbers |
设置是否在每个表格行的开头显示行号 | |
hide_totals |
设置表格可视化图表是否显示列总计 | |
hide_row_totals |
设置表格可视化图表是否显示行总计 | |
transpose |
设置是否将表格行转置为列 | |
hidden_fields |
指定要在查询中使用但在图表中隐藏的所有字段 | |
limit_displayed_rows |
根据行在结果中的位置,在可视化图表中显示或隐藏行 | |
| 系列参数 | ||
truncate_text |
使用省略号 (…) 缩短列标题和数据单元格内的文本 | |
show_view_names |
显示每个列标题的视图名称和字段名称 | |
size_to_fit |
自动调整所有列的宽度,使表格完美适应其所在元素的宽度 | |
dynamic_fields |
在表格图表中包含表计算或自定义字段 | |
series_labels |
为可视化图表中的每一列指定自定义标签 | |
series_column_widths |
指定可视化图表中列的具体宽度 | |
series_cell_visualizations |
指定列是否使用单元格可视化可视化选项。此参数具有子参数 is_active、palette 和 value_display。 |
|
series_text_format |
指定每列的单元格文本布局。此参数具有子参数 fg_color、bg_color、bold、italic 和 align。 |
|
series_collapsed |
指定包含小计的列是否会收起 | |
series_value_format |
使用自定义格式定义列的值格式 | |
| 格式化参数 | ||
color_application |
将颜色应用于单元格可视化图表和条件格式 | |
header_font_color |
为列标题应用字体颜色 | |
header_background_color |
为列标题的背景应用颜色 | |
header_text_alignment |
对列标题应用左对齐、右对齐或居中对齐 | |
header_font_size |
将字体大小应用于列标题 | |
rows_font_size |
将字号应用于数据单元格内的文本 | |
enable_conditional_formatting |
设置为 true,以定义表格可视化图表的颜色编码规则 |
|
conditional_formatting_include_totals |
指定是否在颜色编码方案中包含总计 | |
conditional_formatting_include_nulls |
指定是否应将 null 值表示为零 | |
conditional_formatting |
使用 conditional_formatting 及其子参数来定义为表格可视化图表设置颜色代码的规则 |
|
基本参数
定义 LookML 信息中心元素时,您必须至少为 name 和 type 参数指定值。其他基本参数(例如 title、height 和 width)会影响元素在信息中心内的位置和外观。
name
本部分介绍
name参数,该参数是信息中心元素的一部分。
name也可以用作信息中心过滤条件的一部分,如信息中心参数文档页面中所述。
每个 name 声明都会创建一个新的信息中心元素并为其分配一个名称。
元素名称必须是唯一的。当您使用 layout: grid 信息中心时,有时会在 elements 参数中引用名称;当您将元素整理到图块组 (type: group) 中时,有时会在子元素的 group 参数中引用名称。
- name: orders_by_date
title
本部分介绍
title参数,该参数是信息中心元素的一部分。
title也可以用作信息中心的一部分,如信息中心参数文档页面中所述。
title也可以用作信息中心过滤条件的一部分,如信息中心参数文档页面中所述。
借助 title 参数,您可以更改元素名称向用户显示的方式。如果未指定,标题默认为元素 name。
请参考下面的示例:
- name: sales_overview
title: '1) Sales Overview'
如果您使用此格式,则该元素不会显示为销售概览,而是显示为1) 销售概览。
type
本部分介绍
type参数,该参数是信息中心元素的一部分。
type也可以用作信息中心过滤条件的一部分,如信息中心参数文档页面中所述。
type也可以用作联接的一部分,如type(用于联接)参数文档页面中所述。
type也可以用作维度的一部分,如维度、过滤条件和参数类型文档页面中所述。
type也可以用作测量的一部分,如测量类型文档页面中所述。
type 参数用于确定要在元素中使用的可视化图表类型。
- name: element_name
type: text | looker_grid | table | single_value | looker_single_record |
looker_column | looker_bar | looker_scatter | looker_line | looker_area |
looker_pie | looker_donut_multiples | looker_funnel | looker_timeline |
looker_map | looker_google_map | looker_geo_coordinates | looker_geo_choropleth |
looker_waterfall | looker_wordcloud | looker_boxplot | button | group
如需简要了解不同类型的 LookML 信息中心元素,请参阅 type(适用于 LookML 信息中心)文档页面。
height
本部分介绍
height参数,该参数是信息中心元素的一部分。
height也可以用作信息中心行的一部分,如信息中心参数文档页面中所述。
对于采用 tile 或 static 布局的信息中心
height 参数用于定义元素的高度,单位为 tile_size(以像素为单位),适用于 layout: tile 和 layout: static 信息中心。
例如,以下代码指定了 tile_size: 100 和 height: 4,使 orders_by_date 元素的高度为 400 像素。
- dashboard: sales_overview
tile_size: 100
...
elements:
- name: orders_by_date
height: 4
...
对于采用 newspaper 布局的信息中心
height 参数以行为单位定义 layout: newspaper 信息中心内元素的高度。
采用报纸布局的信息中心默认元素高度为 6 行,即大约 300 像素。对于 preferred viewer 参数设置为 dashboards-next 的信息中心,最小高度为 1 行。对于 preferred viewer 参数设置为 dashboards 的信息中心,最小高度为 2 行。
例如,以下代码会将一个元素设置为 12 行高,即其他设置为默认值的元素的两倍高:
- dashboard: sales_overview
layout: newspaper
...
elements:
- name: orders_by_date
height: 12
...
width
本部分介绍
width参数,该参数是信息中心元素的一部分。
width也可以用作信息中心的一部分,如信息中心参数文档页面中所述。
width 参数用于定义 layout: tile 和 layout: static 信息中心内元素的宽度,单位为 tile_size。
例如,以下代码指定了 tile_size: 100 和 width: 4,使 orders_by_date 元素的宽度为 400 像素。
- dashboard: sales_overview
tile_size: 100
...
elements:
- name: orders_by_date
width: 4
...
width 参数用于定义 layout: newspaper 信息中心内元素的宽度(以列为单位)。
采用报纸布局的信息中心默认宽度为 24 列。
例如,以下代码会将元素设置为信息中心宽度的一半:
- dashboard: sales_overview
layout: newspaper
...
elements:
- name: orders_by_date
width: 12
...
top
top 参数定义元素从上到下的位置,单位为 tile_size,适用于 layout: static 信息中心。
例如,以下代码指定了 tile_size: 100 和 top: 4,将 orders_by_date 元素的上边缘定位在距离信息中心顶部 400 像素的位置。
- dashboard: sales_overview
tile_size: 100
...
elements:
- name: orders_by_date
top: 4
...
left
left 参数用于定义元素在 layout: static 信息中心内从左到右的位置,以 tile_size 为单位。
例如,以下代码指定了 tile_size: 100 和 left: 4,将 orders_by_date 元素的左边缘定位在距离信息中心左侧 400 像素的位置。
- dashboard: sales_overview
tile_size: 100
...
elements:
- name: orders_by_date
left: 4
...
row
对于 layout: newspaper 信息中心,row 参数定义元素上边缘所在的行。如果使用 group 参数将元素放置在图块组内,则 row 会定义元素相对于组容器 (row: 0) 顶部的行位置。
信息中心从顶部的第 0 行开始。采用报纸布局的信息中心默认元素高度为 6 行,这意味着信息中心顶部的元素 (row: 0) 默认会占用第 0-5 行。
每行高 50 像素,这意味着默认元素高度(6 行)为 300 像素。
例如,以下代码会将一个元素设置为位于信息中心内的第二行元素中(假设元素设置为默认高度):
- dashboard: sales_overview
layout: newspaper
...
elements:
- name: orders_by_date
row: 6
...
col
对于 layout: newspaper 信息中心,col 参数定义元素左边缘所在的列。如果使用 group 参数将元素放置在图块组内,则 col 会定义元素相对于组容器 (col: 0) 左边缘的列位置。
信息中心分为 24 列。信息中心从左侧的第 0 列开始。采用报纸布局的信息中心默认元素宽度为 8 列,这意味着信息中心左侧的信息中心元素 (col: 0) 默认会占用第 0-7 列。
例如,以下代码会将一个元素设置为信息中心内第三列元素:
- dashboard: sales_overview
layout: newspaper
...
elements:
- name: orders_by_date
col: 16
...
refresh
本部分介绍
refresh参数,该参数是信息中心元素的一部分。
refresh也可以用作信息中心的一部分,如信息中心参数文档页面中所述。
refresh 参数允许元素定期自动重新加载,从而检索最新数据。这在持续显示信息中心的环境中(例如在办公室电视上)通常很有用。请注意,信息中心必须在浏览器窗口中打开,此参数才能生效。此设置不会在后台运行以“预热”信息中心缓存。
刷新频率可以是任意秒数、分钟数、小时数或天数(不含小数)。例如:
- name: orders_by_date
refresh: 2 hours
设置较短的刷新间隔时,请务必谨慎。如果元素背后的查询需要大量资源,某些元素可能会给数据库带来超出预期的压力。
note_state
note_state 参数定义了当备注过大而无法在元素宽度内单行显示时,是折叠还是展开。如果您选择 collapsed,并且备注过长,则备注会以可点击的省略号 (...) 结尾,点击该省略号即可阅读完整备注。如果您选择expanded,并且备注较长,则备注会换行显示。
note_display
note_display 参数用于定义备注在元素上的显示位置。above 会将备注置于元素顶部,below 会将备注置于元素底部,hover 则要求用户将鼠标悬停在 ? 图标上才能看到备注。
note_text
note_text 参数用于指定元素备注中显示的文本。
查询参数
定义 LookML 信息中心元素时,您必须至少为 model 和 explore 查询参数指定值,并且必须使用 dimensions 参数、measures 参数或 fields 参数至少指定一个字段。您还可以使用本部分中所述的其他查询参数来控制数据在信息中心元素中的显示方式。
model
model 参数定义要用于元素查询的模型。如果未指定,则默认为信息中心所在的模型。
- name: orders_by_date
model: ecommerce
model 参数接受 LookML 常量。您可以在项目的清单文件中定义一个常量,然后使用语法 "@{constant_name}" 将该常量设置为 model 的值。使用常量可让您在一个位置定义模型名称,如果您要更新多个信息中心元素所使用的模型名称,此功能尤为实用。
如需详细了解如何将常量与 LookML 信息中心搭配使用,并查看相关示例,请参阅 constant 参数文档页面。
explore
本部分介绍
explore参数,该参数是信息中心元素的一部分。
explore也可以用作模型的一部分,如explore参数文档页面中所述。
explore也可以用作信息中心过滤条件的一部分,如信息中心参数文档页面中所述。
explore 参数定义了要用于元素查询的探索。
- name: orders_by_date
explore: order
explore 参数接受 LookML 常量。您可以在项目的清单文件中定义一个常量,然后使用语法 "@{constant_name}" 将该常量设置为 explore 的值。使用常量可让您在一个位置定义探索的名称,如果您要更新多个信息中心元素使用的探索的名称,这会特别有用。
如需详细了解如何将常量与 LookML 信息中心搭配使用,并查看相关示例,请参阅 constant 参数文档页面。
fields
fields 参数定义要用于元素查询的字段。使用语法 view_name.dimension_name 指定字段。
## single field example
- name: orders_by_date
fields: order.order_date
## multiple fields example
- name: orders_by_date
fields: [order.order_date, order.order_count]
如果您使用 fields 参数,则无需使用 dimensions 和 measures 参数。
dimensions
dimensions 参数定义要用于元素查询的一个或多个维度。使用语法 view_name.dimension_name 指定维度。如果查询没有任何 dimensions,请勿添加。
## single dimension example
- name: orders_by_date
dimensions: order.order_date
## multiple dimension example
- name: orders_by_date
dimensions: [order.order_date, customer.name]
measures
measures 参数定义要用于元素查询的一个或多个测量。使用语法 view_name.measure_name 指定测量。如果查询没有任何 measures,请勿添加。
## single measure example
- name: orders_by_date
measures: order.count
## multiple measure example
- name: orders_by_date
measures: [order.count, order_item.count]
sorts
sorts 参数用于定义元素查询的排序行为。先列出主要排序字段,然后列出所有次要排序字段。使用 view_name.field_name 语法指定要作为排序依据的维度或测量。
如果您省略 sorts 参数,该元素将使用 Looker 的默认排序顺序。升序排序不需要后缀,而降序排序需要 desc 后缀。
以下示例定义了单个排序:
- name: orders_by_date
sorts: order.order_date desc
以下示例定义了多个排序:
- name: orders_by_date
sorts: [order.order_date desc, customer.name]
如果您透视维度,则可以通过指定测量名称、排序方向和数据表中目标列的从 0 开始的索引编号来对查询结果进行排序。例如,以下元素使用索引 0 按第一个透视列排序:
- name: orders_by_category
sorts: [orders.count desc 0]
如需按行总计排序,请指定总计列的索引。例如,以下元素使用索引 2 按行总计排序,该索引表示具有两个透视列的查询的总计列:
- name: orders_by_cohort
sorts: [users.count desc 2]
pivots
pivots 参数定义了应针对元素查询进行透视的维度。使用语法 view_name.dimension_name 指定维度。如果查询没有任何 pivots,请勿添加。
## single pivot example
- name: orders_by_date
pivots: customer.gender
## multiple pivot example
- name: orders_by_date
pivots: [customer.gender, customer.age_tier]
fill_fields
fill_fields 参数用于定义使用维度填充选项的维度。使用语法 view_name.dimension_name 指定尺寸。
- name: orders_by_date
fill_fields: [orders.created_date, orders.shipped_date]
subtotals
subtotals 参数用于定义使用 subtotals 选项的维度。使用语法 view_name.dimension_name 指定尺寸。
subtotals: [products.department, distribution_centers.name]
total
total 参数用于设置是否在表格底部显示总计行。如需了解详情,请参阅显示总计。
total: true | false
## default value: false
row_total
row_total 参数用于设置总计列显示在表格的右侧还是左侧。仅在存在数据透视表时有效。如需了解详情,请参阅显示总计。
row_total: right | left | false
## default value: false
limit
limit 参数定义了元素查询应使用的行数限制。此限制适用于应用任何透视之前的行数。
- name: orders_by_date
limit: 100
column_limit
column_limit 参数定义了元素查询应使用的列限制。此限制适用于应用任何透视后的列数。
- name: orders_by_date
column_limit: 100
filters
本部分介绍
filters参数,该参数是信息中心元素的一部分。
filters也可以用作信息中心的一部分,如信息中心参数文档页面中所述。
filters也可以用作测量的一部分,如filters参数文档页面中所述。
filters 参数定义了应用于元素查询的不可更改的过滤条件。如果您希望用户可以在信息中心内更改过滤条件,则应使用filters(针对信息中心)设置过滤条件,然后使用 listen 将其应用于元素。
filters 的语法为:
- name: element_name
filters:
orders.created_date: 2020/01/10 for 3 days
orders.status: Shipped
# You can create multiple filter statements
每个过滤条件都可以接受 Looker 过滤表达式或值常量。您还可以在过滤表达式中使用 _localization 或 _user_attributes Liquid 变量,以实现灵活的过滤值。
filter_expression
filter_expression 参数为元素的查询定义了不可更改的自定义过滤条件。如果您希望用户可以在信息中心内更改过滤条件,则应使用filters for dashboards 设置过滤条件,然后使用 listen 将其应用于元素。
- name: element_name
filter_expression:
- diff_days(${users.created_date},${user_order_facts.first_order_date}) > 60
Looker 过滤表达式文档页面列出了 Looker 过滤表达式。
listen
借助信息中心过滤条件,查看者可以交互式地优化信息中心元素中显示的数据。使用 filters 参数为 LookML 信息中心定义信息中心过滤条件。然后,使用 listen 参数将信息中心元素关联到信息中心过滤条件。
listen 的语法如下所示:
- name: element_name
listen:
filter_name_goes_here: dimension or measure on which to apply
the filter using view_name.field_name syntax
# You can add more than one listen statement
向元素添加 listen 参数,然后使用 view_name.field_name 语法提供过滤条件的名称,后跟英文冒号和对过滤条件应应用到的字段的引用。例如,您可以创建一个名为日期的过滤条件,要求用户在界面的过滤条件字段中输入日期。然后,您可以将用户输入的值应用于 orders_by_date 元素,如下所示:
- dashboard: sales_overview
...
filters:
- name: date
type: date_filter
elements:
- name: orders_by_date
listen:
date: order.order_date
...
如果所监听的过滤条件配置了 vis_filter: true 参数,则过滤条件控件会直接显示在该可视化图表图块顶部的过滤条件栏中,而不是显示在顶部信息中心过滤条件栏中。
如需查看使用 filters 参数和 listen 参数将信息中心过滤条件应用于各个信息中心元素的其他示例,请参阅构建 LookML 信息中心。
query_timezone
query_timezone 参数指定运行查询的时区。时区选项显示在timezone 的值文档页面上。如果您希望查询使用查看者的时区运行,可以将该值指定为 user_timezone。
- name: orders_by_date
query_timezone: America/Los Angeles
- name: orders_by_customer
query_timezone: user_timezone
analysis_config
以下子参数可用于定义分析:
您可以使用如下语法创建预测:
analysis_config:
- forecasting:
confidence_interval: 0.95
field_name: orders.count
forecast_n: 14
forecast_interval: day
seasonality: 7
forecasting
forecasting是一种分析类型,可将预测应用于可视化图表。借助预测功能,分析师可以快速向新的或现有的“探索”查询添加数据预测,从而帮助用户预测和监控特定数据点。
如需了解详情,请参阅可视化图表中的预测文档页面。
如需向可视化图表添加预测,必须启用预测实验室功能。
confidence_interval
confidence_interval 用于设置预测数据值的边界,这些值以百分比的小数表达式形式输入。confidence_interval 是可选字段,默认情况下为空。
confidence_interval: 0.99 | 0.98 | 0.95 | 0.90 | 0.80
请参阅在可视化图表中进行预测文档页面上的预测区间部分。
如需向可视化图表添加预测,必须启用预测实验室功能。
field_name
field_name 指定要纳入预测的度量名称(最多五个)。
field_name: view_name.field_name
forecast_n
forecast_n 指定预测时长。
forecast_n: N # An integer that represents the length of the forecast
请参阅在可视化图表中进行预测文档页面上的长度部分。
如需向可视化图表添加预测,必须启用预测实验室功能。
forecast_interval
forecast_interval 用于设置预测数据值的时长间隔。forecast_interval 会根据“探索”查询中的时间范围维度自动填充。
forecast_interval: day | month # a timeframe with dimension fill
请参阅长度文档页面。
如需向可视化图表添加预测,必须启用预测实验室功能。
seasonality
seasonality 可让分析师在预测中考虑已知的周期或重复的数据趋势。seasonality 是可选字段,默认情况下为空。
seasonality: N # An integer that represents the number of rows over which a cycle or pattern repeats
自动季节性设置表示为空白 seasonality 值。
请参阅可视化图表中的预测文档页面上的季节性部分。
如需向可视化图表添加预测,必须启用预测实验室功能。
merged_queries
借助 merged_queries 参数,您可以将多个查询的结果合并到一个信息中心元素中。在元素的 merged_queries 参数中定义每个源查询,并使用 join_fields 子参数指定应如何合并结果。
以下 LookML 示例代码创建了一个合并结果元素 type: looker_grid。在此示例中,merged_queries 参数用于创建一个信息中心元素,该元素将两个单独查询中的数据合并到一个表格图表中:
- name: merged_results_element
title: Merged Results Tile
type: looker_grid
merged_queries:
- model: ecommerce
explore: users
type: table
fields: [users.state, users.count, users.city]
sorts: [users.count desc 0]
limit: 5000
column_limit: 50
query_timezone: UTC
listen:
- State: users.state
- model: ecommerce
explore: users
type: table
fields: [users.state, users.city]
sorts: [users.state]
limit: 500
column_limit: 50
query_timezone: UTC
join_fields:
- field_name: users.state
source_field_name: users.state
- field_name: users.city
source_field_name: users.city
listen:
- State: users.state
在此示例中,信息中心元素合并了两个源查询中的数据,这两个源查询基于 ecommerce 模型中的 users 探索。主查询包含 users.state、users.count 和 users.city 字段,并按 users.count 字段对结果进行排序。第二个源查询包含 users.state 和 users.city 字段,并按 users.state 字段对结果进行排序。
join_field 参数会根据 users.state 和 users.city 字段中的匹配值合并源查询。
listen 参数会将 State 过滤条件应用于这两个查询,这样信息中心查看者就可以通过选择特定州来优化信息中心图块中显示的查询结果。
示例:合并公司数据
假设您要创建一个合并查询,用于合并来自两个不同探索(company_info 和 companies)的公司信息。您希望将每个探索中的 ipo.stock_symbol、companies.name 和 companies.contact_email 字段上的查询联接起来,以创建一个查询,用于返回公司名称、公司联系电子邮件、IPO 年份、股票代码、员工人数和职位数量。您可以在 LookML 中定义合并查询元素,如下所示:
- name: merged_results_element
title: Merged Results Tile
merged_queries:
- model: market_research
explore: company_info
fields: [companies.name, companies.contact_email, ipo.public_year, ipo.stock_symbol]
filters:
companies.contact_email: "-NULL"
ipo.valuation_amount: NOT NULL
sorts: [ipo.public_year desc]
- model: company_data
explore: companies
fields: [companies.name, ipo.stock_symbol, companies.contact_email,
companies.number_of_employees, jobs.job_count]
filters:
companies.number_of_employees: NOT NULL
ipo.stock_symbol: "-NULL"
companies.contact_email: "-NULL"
sorts: [jobs.job_count desc]
join_fields:
- field_name: ipo.stock_symbol
source_field_name: ipo.stock_symbol
- field_name: companies.name
source_field_name: companies.name
- field_name: companies.contact_email
source_field_name: companies.contact_email
对合并的查询元素应用过滤条件
前面的合并查询元素示例演示了如何使用 filters 参数直接在每个源查询中应用硬编码过滤条件。例如,主查询中的过滤条件 companies.contact_email: "-NULL" 和 ipo.valuation_amount: NOT NULL 会将结果限制为具有有效联系电子邮件地址和估值的公司。这些查询级过滤条件会在合并查询之前预过滤数据,用户无法更改。
您还可以通过在每个来源查询的定义中使用 listen 参数,将信息中心过滤条件应用于合并查询元素。例如,假设您有一个名为 Industry 的信息中心过滤条件,该过滤条件是您在信息中心级别使用 filters 参数为 LookML 信息中心定义的:
filters:
- name: Industry
title: Industry
type: field_filter
ui_config:
type: dropdown_menu
display: inline
model: market_research
explore: company_info
field: companies.industry
如需将 Industry 过滤条件应用于两个源查询中的 companies.industry 字段,请将 listen 参数添加到每个合并查询的源查询定义中,如下所示:
listen:
Industry: companies.industry
例如,以下示例代码会将 Industry 过滤条件添加到上一个示例中合并结果元素内的两个源查询。
- name: merged_results_element
title: Merged Results Tile
merged_queries:
- model: market_research
explore: company_info
fields: [companies.name, companies.contact_email, ipo.public_year, ipo.stock_symbol]
filters:
companies.contact_email: "-NULL"
ipo.valuation_amount: NOT NULL
sorts: [ipo.public_year desc]
listen:
Industry: companies.industry
- model: company_data
explore: companies
fields: [companies.name, ipo.stock_symbol, companies.contact_email,
companies.number_of_employees, jobs.job_count]
filters:
companies.number_of_employees: NOT NULL
ipo.stock_symbol: "-NULL"
companies.contact_email: "-NULL"
sorts: [jobs.job_count desc]
join_fields:
- field_name: ipo.stock_symbol
source_field_name: ipo.stock_symbol
- field_name: companies.name
source_field_name: companies.name
- field_name: companies.contact_email
source_field_name: companies.contact_email
listen:
Industry: companies.industry
添加此参数后,当用户与 Industry 信息中心过滤条件互动时,合并查询元素中的相应来源查询也会相应地进行过滤。
列参数
以下参数对应于在表格图表中移动和固定列的功能。
auto_size_all_columns
auto_size_all_columns 参数会根据列标题或最长数据值的宽度(以较宽者为准)自动调整每个表格列的宽度。此参数会替换 series_column_widths 和 size_to_fit 参数(如果已定义)。
- name: orders_by_date
auto_size_all_columns: true
column_order
column_order 参数定义了表格图表中列的顺序。
- name: orders_by_date
column_order: [customer.city, customer.state, customer.count]
pinned_columns
pinned_columns 参数用于定义固定在表格图表左侧的所有列。
- name: orders_by_date
pinned_columns:
orders.created_date: left
distribution_centers.name: left
绘图参数
以下参数对应于表格图表可视化图表编辑器的绘制菜单中的选项。
table_theme
使用 table_theme 参数可将以下表格着色选项之一应用于表格元素:
editable:该表包含蓝色维度、橙色测量和绿色表计算。white:表头为白色,数据行交替显示白色和灰色,文本为黑色。gray:表头为灰色,数据行交替显示白色和浅灰色,文本为深灰色。transparent:表头完全透明,数据行在完全透明和半透明灰色之间交替,文本颜色会根据透出的背景颜色在黑色和白色之间自动调整。如果您使用的是自定义嵌入式信息中心,则将table_theme设置为transparent会很有用,这样可视化图表就会显示图块背景颜色。unstyled:表头和数据行均为白色,文本为黑色。
table_theme: editable | white | gray | transparent | unstyled
show_row_numbers
show_row_numbers 参数用于设置是否在每个表格行的开头显示行号。
show_row_numbers: true | false
hide_totals
如果您的探索包含列总计,hide_totals 会设置可视化图表是否显示总计。
hide_totals: true | false
hide_row_totals
如果您的探索包含行总计,hide_row_totals 会设置行总计是否显示在可视化图表中。
hide_row_totals: true | false
transpose
借助 transpose 参数,您可以将表行转置为列。接受 true 或 false。
- name: orders_by_date
transpose: true
hidden_fields
hidden_fields 参数指示查询中使用了哪些字段(如果有),但在图表中隐藏了这些字段。所有隐藏字段都会显示在“探索”的数据表部分中。
hidden_fields: [inventory_items.count, distribution_centers.id]
limit_displayed_rows
借助 limit_displayed_rows 参数,您可以根据行在结果中的位置,在可视化图表中显示或隐藏行。例如,如果可视化图表显示 7 天滚动平均值,您可能需要隐藏前 6 行。如果将此参数设置为 true,您可以使用 limit_displays_rows_values 参数及其子参数指定此参数适用的可视化图表中的值和位置。
limit_displayed_rows: true
limit_displayed_rows_values:
show_hide: hide | show
first_last: first | last
num_rows: '10'
limit_displayed_rows_values
将 limit_displayed_rows_values 参数及其子参数 show_hide、first_last 和 num_rows 与 limit_displayed_rows 搭配使用,可指定要在可视化图表中显示或隐藏的行。如需查看用法示例,请参阅 limit_displayed_rows 部分。
show_hide
show_hide 子参数用于设置是否在可视化图表中隐藏特定行。将 show_hide 设置为 show,以便在可视化图表中仅显示有限数量的行;将 show_hide 设置为 hide,以便从可视化图表中排除某些行。
first_last
first_last 子参数用于设置要隐藏或显示的行是结果集中的前几行还是后几行。将 first_last 设置为 first 会显示或隐藏前几行,而将 first_last 设置为 last 会显示或隐藏最后几行。
num_rows
num_rows 子参数用于设置要隐藏或显示的行数。例如,num_rows: '10' 将在可视化图表中显示或隐藏结果集的前 10 行或后 10 行。
系列参数
以下参数对应于表格图表可视化编辑器中系列菜单中的选项。
truncate_text
truncate_text 参数用于设置是否应使用省略号 (…) 缩短列标题和数据单元格内的文本。
truncate_text: true | false
show_view_names
show_view_names 参数决定了是否在图表标签(例如轴名称和列名称)中显示视图名称。
show_view_names: true | false
## default value: true
size_to_fit
size_to_fit 参数用于设置是否调整所有列的宽度,以便表格完美契合查看表格的元素的宽度。如果 auto_size_all_columns 参数设置为 true,则会覆盖 size_to_fit。
size_to_fit: true | false
dynamic_fields
dynamic_fields 参数及其子参数描述了要与可视化图表搭配使用的任何表计算或自定义字段。您必须拥有创建自定义字段的权限,才能添加最多 255 个字符的 description,或将 calculation_type 用于自定义组或自定义分箱。您必须拥有创建表计算的权限,才能向表计算添加最多 255 个字符的 description,或在快捷计算中使用 calculation_type。
以下子参数可用于定义动态字段:
table_calculationmeasuredimensionlabelbased_ontypeexpressionfilter_expressionvalue_formatvalue_format_namecalculation_typeargs_kind_hint_type_hintis_disableddescription
您可以使用如下语法创建表计算:
dynamic_fields:
- table_calculation: running_total
label: Running Total of Items
expression: running_total(${inventory_items.count})
value_format_name: decimal_0
description: your description of up to 255 characters here
_kind_hint: measure
_type_hint: number
is_disabled: false
dynamic_fields:
- category: table_calculation
description: your description of up to 255 characters here
label: Percent of Orders Count
value_format:
value_format_name: percent_0
calculation_type: percent_of_column_sum
table_calculation: percent_of_orders_count
args:
- orders.count
_kind_hint: measure
_type_hint: number
- category: table_calculation
description: your description of up to 255 characters here
label: Percent of previous - Orders Count
value_format:
value_format_name: percent_0
calculation_type: percent_of_previous
table_calculation: percent_of_previous_orders_count
args:
- orders.count
_kind_hint: measure
_type_hint: number
- category: table_calculation
description: your description of up to 255 characters here
label: Percent change from previous - Orders Count
value_format:
value_format_name: percent_0
calculation_type: percent_difference_from_previous
table_calculation: percent_change_from_previous_orders_count
args:
- orders.count
_kind_hint: measure
_type_hint: number
- category: table_calculation
description: your description of up to 255 characters here
label: Rank of Orders Count
value_format: ## this field is optional
value_format_name: ## this field is optional
calculation_type: rank_of_column
table_calculation: rank_of_orders_count
args:
- orders.count
_kind_hint: measure
_type_hint: number
- category: table_calculation
description: your description of up to 255 characters here
label: Running total of Orders Count
value_format: ## this field is optional
value_format_name: ## this field is optional
calculation_type: running_total
table_calculation: running_total_of_orders_count
args:
- orders.count
_kind_hint: measure
_type_hint: number
您可以使用如下语法创建自定义度量,以便在可视化图表中使用:
dynamic_fields:
- measure: avg_sale_price
label: Average Sale Price
based_on: products.sale_price
type: average
value_format_name: usd
description: your description of up to 255 characters here
_kind_hint: measure
_type_hint: number
您可以使用如下语法创建经过过滤的自定义度量,以便在可视化图表中使用:
dynamic_fields:
- measure: order_count_for_25_47_year_olds
based_on: order_items.order_count
type: count_distinct
label: Order Count for 25- to 47-Year-Olds
description: your description of up to 255 characters here
value_format: 00#
_kind_hint: measure
_type_hint: number
filter_expression: "${users.age} >= 25 AND ${users.age} <= 47"
您可以使用如下语法创建自定义维度,以便在可视化图表中使用:
dynamic_fields:
- dimension: user_city_state
label: User City and State
expression: concat(${users.city}, ", ", ${users.state})
description: your description of up to 255 characters here
_kind_hint: dimension
_type_hint: string
您可以使用如下语法为要在可视化图表中使用的维度创建自定义组:
- category: dimension
description: 'States by region'
label: State Groups
value_format: ## this field is optional
value_format_name: ## this field is optional
calculation_type: group_by
dimension: state_groups
args:
- users.state
- - label: Pacific Northwest
filter: Oregon,Idaho,Washington
- Other
_kind_hint: dimension
_type_hint: string
您可以为要在可视化图表中使用的维度创建自定义分箱,语法如下:
- category: dimension
description: Order item sale prices, in tiers of 10
label: Sale Price Bins
value_format:
value_format_name:
calculation_type: bin
dimension: sale_price_bins
args:
- order_items.sale_price
- '10'
- '0'
- '100'
-
- classic
_kind_hint: dimension
_type_hint: string
您可以向元素添加多个动态字段。您无需将表计算添加到 fields 参数中,即可在可视化图表中显示它们,但您需要将其他类型的动态字段添加到 fields 中,才能显示它们。
table_calculation
如果您要定义表计算,则 table_calculation 子参数会为表计算命名。这是在 LookML 中引用表计算时要使用的名称。
measure
measure 子参数用于定义自定义度量或经过滤的自定义度量的名称。这是您在 LookML 中引用测量时使用的名称。
dimension
dimension 子参数用于定义自定义维度的名称。这是在 LookML 中引用维度时要使用的名称。
label
label 子参数用于定义动态字段的标题,该标题将显示在可视化图表中。此名称可能与 table_calculation、measure 或 dimension 子参数中指定的名称相同,也可能不同。
based_on
如果您使用的是自定义度量或经过过滤的自定义度量,则 based_on 子参数会使用 view_name.field_name 语法标识其所基于的度量。
type
如果您使用的是自定义度量,type 子参数会标识汇总类型。它接受 count_distinct、sum、average、min、max 或 median。
description
您可以使用 description 子参数为任何自定义字段或表计算添加最多 255 个字符的说明。当用户在字段选择器中点击字段名称右侧的信息图标时,以及当用户在“探索”、信息中心或 Look 中的表格或表格图表可视化图表中将鼠标悬停在列名称上时,Looker 会显示说明。
expression
如果您使用的是表计算,则 expression 子参数会定义用于创建表计算的 Looker 表达式。
filter_expression
如果您使用的是自定义过滤测量,filter_expression 子参数会定义用于过滤测量的 Looker 表达式。
value_format
如果您使用自定义格式,则可选的 value_format 子参数会定义动态字段的值格式。如果您想使用默认 Looker 格式,请改用 value_format_name。
value_format_name
可选的 value_format_name 子参数会将默认格式应用于动态字段。如果您想使用自定义格式,请改用 value_format。
calculation_type
calculation_type 子参数定义了快捷计算或分组函数的类型,用于创建表计算或为维度创建自定义分组:
自定义字段 calculation_type 选项:
group_by- 根据指定的自定义条件,将维度值归入自定义固定标签下。类似于 SQL 中的CASE WHEN或 LookMLcase字段参数。bin- 针对数值类型维度和自定义维度,将值分组到自定义分箱或层级中。类似于 LookMLtier维度类型。
表计算 calculation_type 选项:
percent_of_column_sum- 行值除以相应列中各值之和。此计算仅包含达到查询行数上限时数据表中的值。percent_of_previous- 当前行的值除以下一行的值。percent_difference_from_previous- 当前行的值与下一行的值之差除以下一行的值。rank_of_column- 行的值在相应列所有值中的排名。此计算仅包含达到查询行数上限时数据表中的值。running_total- 当前行的值与该列中前面所有行的值的累计总和。percent_of_previous_column- 对于透视字段,当前列的值除以左侧一列的值。percent_change_from_previous_column- 对于透视字段,当前列的值与左侧一列的值之差除以左侧一列的值。percent_of_row- 对于透视字段,当前列的值除以该字段所在行的总和所得的百分比。running_row_total- 对于透视字段,当前列与所在行中前面所有列的累计总和。
args(针对自定义群组)
如果您对某个维度使用自定义组,则 args 会指定用于向维度值应用固定标签的参数。args 采用以下格式:
args:
- view_name.field_name
- label: specified custom label
filter: condition for values
- label: another specified custom label
filter: a different condition for values
- Other ## An optional customizable group label for values that do not meet specified conditions.
您可以根据需要添加任意数量的 label 和 filter 条件,具体取决于所需的群组数量。
如需参考,请参阅前面的示例。
args(自定义分箱)
如果您要为数值维度使用自定义分箱,args 会指定用于对维度值应用固定层级的实参。args 采用以下格式:
args:
- view_name.field_name
- bin_size ## The numeric interval on which to base each bin, in single quotes
- min ## The numeric value of the minimum bin size, in single quotes
- max ## The numeric value of the maximum bin size, in single quotes
- override ## A value will only appear when a custom bin uses a Custom-sized bin type.
- style ## The bin display style. Currently, only classic is supported.
如需参考,请参阅前面的示例。
args(用于快捷计算)
args 子参数用于指定您要用于快捷计算的数值字段的名称。参数采用以下格式:
- args:
- view_name.field_name ## the field on which the calculation is based
如需参考,请参阅前面的示例。
_kind_hint
可选的 _kind_hint 子参数用于标识动态字段返回的是维度还是测量。它接受 dimension 和 measure 值。
_type_hint
可选的 _type_hint 子参数用于标识动态字段的表达式应生成的数据类型。
is_disabled
可选的 is_disabled 子参数用于指定表计算是否显示在可视化图表及其底层“探索”中。它接受 true 和 false 值。
series_labels
使用 name: label 对,根据系列名称设置一个或多个系列的标签。
对于透视图表,系列名称即为透视名称。
series_labels:
'Yes': iOS Users
'No': Android Users
对于包含多个测量值的图表,系列名称即为测量值字段名称。
series_labels:
inventory_items.count: Inventory
orders.count: Orders
series_column_widths
根据系列名称设置一列或多列的宽度。如果 auto_size_all_columns 参数设置为 true,则会覆盖 series_column_widths。
series_column_widths:
order_times.shipping_time: 50
orders.count: 60
series_cell_visualizations
通过使用 view_name.field_name 格式指明系列名称,指定一个或多个列是否使用单元格可视化选项。series_cell_visualizations 具有子参数 is_active、palette 和 value_display。
series_cell_visualizations:
order_items.count:
is_active: true
palette:
palette_id: my-custom-colors-sequential-0
collection_id: my-custom-colors
value_display: true
is_active
可选的 is_active 子参数接受 true 或 false,用于指示是否为该系列启用条形可视化图表。如果未定义 is_active,则默认为 true。
palette
palette 子参数是可选的。如果未使用,调色板将默认为实例默认颜色集合中的发散调色板。
如果使用 palette,则子参数 palette_id 和 collection_id 会将特定调色板中的颜色应用于条形可视化图表。对于 palette_id,您必须使用依序或发散调色板的 ID。如需详细了解调色板 ID 和颜色集合 ID,请参阅 color_application 部分。
palette 有一个备用子参数 custom_colors,用于设置 2 到 5 种自定义颜色,以供条形图使用:
series_cell_visualizations:
order_items.count:
palette:
custom_colors:
- orange
- "#0000ff"
- red
value_display
可选的 value_display 子参数接受 true 或 false,用于指示是否在单元格可视化图表中显示每个数据单元格的值。如果未定义 value_display,则默认为 true。
series_text_format
series_text_format 参数及其子参数用于指定每列的单元格文本布局。要设置格式的系列使用 view_name.field_name 语法表示,子参数用于描述格式。
所有子参数均为可选参数;仅使用您需要的子参数。
series_text_format:
order_items.shipping_time:
align: right
order_items.shipped_date:
align: center
fg_color: "#EA8A2F"
bg_color: "#64518A"
bold: true
italic: true
fg_color
fg_color 子参数用于指示单元格文本的字体颜色。颜色值可以采用十六进制字符串(例如 #2ca6cd)或 CSS 命名颜色字符串(例如 mediumblue)。
bg_color
bg_color 子参数用于指示单元格背景颜色。颜色值可以采用十六进制字符串(例如 #2ca6cd)或 CSS 命名颜色字符串(例如 mediumblue)。
bold
bold 子参数指示单元格文本是否为粗体,并接受 true 或 false。
italic
italic 子参数指示单元格文本是否为斜体,并接受 true 或 false。
align
align 子参数表示单元格文本的对齐方式,接受 left、center 或 right。
series_collapsed
series_collapsed 参数用于定义是收起还是展开特定系列的分类汇总。使用 view_name.field_name 语法和 true 或 false 识别系列。
series_collapsed:
users.city: false
users.state: true
如果该列处于收起状态,点击数据单元格左侧的箭头即可显示构成小计的各个元素。
series_value_format
series_value_format 参数用于指定要应用于系列的格式,该格式独立于应用于底层维度或测量值的任何格式。如果未指定 series_value_format,则值会以底层维度或测量值的格式显示。
使用 view_name.field_name 语法标识要设置格式的系列。
通过 format_string 子参数,您可以使用 Excel 样式格式设置来定义序列的格式。
series_value_format:
products.retail_price:
format_string: "$#,##0.00"
您还可以按如下方式定义格式:
series_value_format:
order_items.count: "00#"
format_string 子参数中使用的格式与 value_format LookML 参数中使用的格式相同。如需了解如何指定这些格式,请参阅向数字字段添加自定义格式文档页面。
格式设置参数
以下参数对应于表格图表可视化编辑器格式设置菜单中的选项。
color_application
color_application 参数及其子参数 collection_id 和 palette_id 可用于将特定颜色集合和调色板应用于信息中心元素。如需简要了解 Looker 的原生颜色集合,请参阅颜色集合文档页面。
如果您知道要使用的调色板的合集 ID 和调色板 ID,可以将这些 ID 输入到 collection_id 和 palette_id 子参数中。集合 ID 或调色板 ID 可以是字母数字代码,也可以基于颜色集合的名称。Looker 的原生集合使用字母数字代码。它们是实例专用的,如下所示:
color_application:
collection_id: 1297dk12-86a7-4xe0-8dfc-82de20b3806a
palette_id: 93c8aeb7-3f8a-4ca7-6fee-88c3617516a1
自定义颜色集合使用基于颜色集合名称的集合和调色板 ID,这些 ID 可在实例之间移植,如下所示:
color_application:
collection_id: blue-tone-collection
palette_id: blue-tone-collection-categorical-0
您还可以使用界面查找所需的颜色、集合或调色板,并生成 LookML 以将其添加到信息中心。前往某个用户定义的内容(例如 Look、信息中心或探索),然后使用界面将所需的颜色、集合或调色板应用于该内容的可视化图表。完成此操作后,您可以按照获取信息中心 LookML 的步骤操作,复制生成的 LookML,并将其粘贴到 color_application 部分。
header_font_color
header_font_color 参数用于为列标题应用字体颜色。
颜色值可以采用十六进制字符串(例如 #2ca6cd)或 CSS 命名颜色字符串(例如 mediumblue)。
header_font_color: purple
默认颜色取决于使用 table_theme 参数定义的表格主题。
header_background_color
header_background_color 参数用于为背景列标题应用颜色。
颜色值可以采用十六进制字符串(例如 #2ca6cd)或 CSS 命名颜色字符串(例如 mediumblue)。
header_background_color: #add8e6
默认颜色取决于使用 table_theme 参数定义的表格主题。
header_text_alignment
header_text_alignment 参数会将 left、right 或 center 对齐方式应用于列标题。
header_text_alignment: center
默认对齐方式为 left。
header_font_size
header_font_size 参数会将 1 到 99 之间的字体大小应用于列标题。
header_font_size: 16
标题和行字体的默认大小为 12。
rows_font_size
rows_font_size 参数会将 1 到 99 的字号应用于数据单元格内的文本,但不会应用于列标题。
rows_font_size: 8
标题和行字体的默认大小为 12。
enable_conditional_formatting
将 enable_conditional_formatting 设置为 true 后,您可以定义规则,按比例或通过指定感兴趣的值对表格可视化图表进行颜色编码。
enable_conditional_formatting: true | false
conditional_formatting_include_totals
如果 enable_conditional_formatting 设置为 true,conditional_formatting_include_totals 会指定是否在颜色编码方案中包含总计。
conditional_formatting_include_totals: true | false
conditional_formatting_include_nulls
如果 enable_conditional_formatting 设置为 true,则 conditional_formatting_include_nulls 会指定是否应将 null 值表示为零。
conditional_formatting_include_nulls: true | false
conditional_formatting
将 enable_conditional_formatting 设置为 true 后,使用 conditional_formatting 参数定义规则,以便对表格可视化图表进行颜色编码。对于每个条件格式规则,您可以使用以下参数指定设置:
以下是条件格式规则的一个示例:
conditional_formatting: [{type: less than, value: 20, background_color: "#9fdee0",
font_color: "#b15928", bold: true, italic: false, strikethrough: false,
fields: [order_items.count], color_application: {collection_id: my-custom-colors,
palette_id: my-custom-colors-sequential-0}}]
type
type 参数用于指定是根据刻度还是根据逻辑条件为值设置颜色编码。
如果您要对某个范围内的值进行颜色编码,可以将 type 设置为 along a scale...。
如果您要根据逻辑条件对值进行颜色编码,可以为 type 指定以下值之一,并为 value 指定一个值:
equal to:规则适用于与为value指定的数字相等的值。not equal to:规则适用于不等于为value指定的数字的值。greater than:规则适用于大于为value指定的数字的值。less than:规则适用于小于为value指定的数字的值。between:规则适用于介于为value指定的两个数字之间的值。not between:规则适用于不介于为value指定的两个数字之间的值。'null':该规则仅适用于 null 值。not null:该规则仅适用于非 null 值。
type: along a scale... | equal to | not equal to | less than | between | not between | 'null' | not null
value
如果您要根据 'null' 或 not null 以外的逻辑条件对值进行颜色编码,请指定规则适用的值。value 参数接受单个数字,或者当 type 设置为 between 或 not between 时,接受一组两个数字。
value: N | [N, N]
background_color
如果您的颜色编码基于逻辑条件(type 设置为 along a scale... 以外的任何值),请使用 background_color 参数为规则适用的值指定背景颜色。
background_color: "#49cec1"
font_color
如果您的颜色编码基于逻辑条件(type 设置为 along a scale... 以外的任何值),请使用 font_color 参数为规则适用的值指定字体颜色。
font_color: "#1f3e5a"
color_application
color_application 参数及其子参数 collection_id、palette_id 和 options 可用于将特定颜色集合和调色板应用于条件格式规则。
如果您有集合 ID 和调色板 ID,则可以按集合 ID 和调色板 ID 向 LookML 信息中心添加颜色。您还可以使用界面找到所需的颜色,并生成 LookML 以将其添加到信息中心。前往某个用户定义的内容(例如 Look、信息中心或探索),然后使用界面将所需颜色应用于该内容的可视化图表。完成此操作后,您可以按照获取信息中心 LookML 的步骤操作,复制生成的 LookML,并将其粘贴到 color_application 部分。如需简要了解 Looker 的预定义颜色集合,请参阅颜色集合文档页面。
当您将 type 设置为 along a scale... 时,可以使用 options 子参数。它具有以下子参数:
steps:此参数会将所用颜色的数量限制为指定值,并将数据分成相应数量的组。如果不使用此参数,系统会根据覆盖整个调色板的渐变色为数据着色。它接受2到100之间的值。mirror:如果设置为true,此参数会在调色板的两侧应用相等的颜色偏移,以便在定义的中心点两侧显示相等的值。接受true或false。constraints:此参数用于设置条件格式适用的数据范围,并设置用于应用调色板的中心点。它接受以下语法:constraints: {min: {type: number, value: 3}, max: {type: percentile, value: 99}, mid: {type: average}}reverse:此参数决定了在应用颜色时是否反转调色板。接受true或false。
bold
根据逻辑条件进行颜色编码时,请设置是否将规则适用的值设为粗体。
bold: true | false
italic
根据逻辑条件进行颜色编码时,请设置是否将规则适用的值设为斜体。
italic: true | false
strikethrough
根据逻辑条件进行颜色编码时,设置是否对规则的值应用删除线格式。
strikethrough: true | false
fields
指定规则应应用于哪些字段。默认情况下,该规则会应用于所有数字字段。
fields: [ view_name.field_name ]