docs-lens-chart-settings
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese—
从源代码验证 Kibana Lens 图表设置
<!-- Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
or more contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright
ownership. Elasticsearch B.V. licenses this file to you under
the Apache License, Version 2.0 (the "License"); you may
not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License. -->
记录 Lens 图表设置时,务必对照 Kibana 源代码核实标签、选项和渲染顺序。不要猜测 UI 标签。
Verifying Kibana Lens Chart Settings from Source Code
关键原则
When documenting Lens chart settings, always verify labels, options, and rendering order against the Kibana source code. Do NOT guess UI labels.
- UI 标签来自 i18n 字符串——始终提取准确的标签。
defaultMessage - JSX 中的渲染顺序 = UI 中的渲染顺序——按照它们在组件树中出现的相同顺序记录设置。
- 条件渲染无处不在——许多设置只会出现在特定条件下(图表类型、所选选项、维度数量)。必须追踪这些条件。
- 共享组件会按图表进行参数化——同一个 组件会根据 props,在 Treemap、Waffle 和 Pie 之间表现出不同行为。
LegendSettings
Key Principles
源代码目录结构
—
分区图表(pie、donut、treemap、mosaic、waffle)
- UI labels come from i18n strings — always extract the exact label.
defaultMessage - Rendering order in JSX = rendering order in the UI — document settings in the same order they appear in the component tree.
- Conditional rendering is everywhere — many settings only appear under specific conditions (chart type, selected options, number of dimensions). Trace the conditions.
- Shared components are parameterized per chart — the same component behaves differently for treemaps vs waffle vs pie based on props.
LegendSettings
所有分区类型的图表都共享以下目录下的代码:
x-pack/platform/plugins/shared/lens/public/visualizations/partition/
├── partition_charts_meta.ts # Per-chart config (toolbar options, legend config)
├── toolbar/
│ ├── style_settings.tsx # Orchestrates Style panel sections
│ ├── titles_and_text_settings.tsx # Slice labels + Slice values options
│ ├── appearance_settings.tsx # Donut hole (pie/donut only)
│ └── legend_settings.tsx # Partition-specific legend wrapper共享 Legend 组件:
x-pack/platform/plugins/shared/lens/public/shared_components/legend/
├── legend_settings.tsx # Main legend settings (Visibility, Size, Truncation, Nested, Stats)
├── location/legend_location_settings.tsx # Position (only when `location` prop is defined)
└── size/legend_size_settings.tsx # Width/Size dropdownSource Code Layout
其他图表类型
Partition charts (pie, donut, treemap, mosaic, waffle)
—
All partition-type charts share code under:
x-pack/platform/plugins/shared/lens/public/visualizations/partition/
├── partition_charts_meta.ts # Per-chart config (toolbar options, legend config)
├── toolbar/
│ ├── style_settings.tsx # Orchestrates Style panel sections
│ ├── titles_and_text_settings.tsx # Slice labels + Slice values options
│ ├── appearance_settings.tsx # Donut hole (pie/donut only)
│ └── legend_settings.tsx # Partition-specific legend wrapperShared legend component:
x-pack/platform/plugins/shared/lens/public/shared_components/legend/
├── legend_settings.tsx # Main legend settings (Visibility, Size, Truncation, Nested, Stats)
├── location/legend_location_settings.tsx # Position (only when `location` prop is defined)
└── size/legend_size_settings.tsx # Width/Size dropdown每种图表类型在 下都有自己的目录:
visualizations/- :bar、line、area
visualizations/xy/ visualizations/heatmap/visualizations/gauge/visualizations/metric/visualizations/tagcloud/
Other chart types
验证工作流
—
第 1 步:查找图表元数据
Each chart type has its own directory under :
visualizations/- for bar, line, area
visualizations/xy/ visualizations/heatmap/visualizations/gauge/visualizations/metric/visualizations/tagcloud/
对于分区图表,请从 开始。该文件为每种图表定义:
partition_charts_meta.ts- ——Slice labels 选项(若无则为空数组)
toolbar.categoryOptions - ——Slice values 选项(若无则为空数组)
toolbar.numberOptions - ——Donut hole 选项(仅 pie/donut)
toolbar.emptySizeRatioOptions - ——是否完全禁用 Style 面板(waffle)
toolbar.isDisabled - ——启用 Legend 中的 Statistics/Show value(仅 waffle)
legend.defaultLegendStats - ——隐藏 Nested 开关(waffle)
legend.hideNestedLegendSwitch - ——Auto 模式下 Legend 的默认可见性行为
legend.getShowLegendDefault - ——Group by 维度的最大数量
maxBuckets
Verification Workflow
第 2 步:追踪 Style 设置
Step 1: Find the chart metadata
—
For partition charts, start with . This file defines per-chart:
partition_charts_meta.ts- — Slice labels options (or empty array if none)
toolbar.categoryOptions - — Slice values options (or empty array if none)
toolbar.numberOptions - — Donut hole options (pie/donut only)
toolbar.emptySizeRatioOptions - — Whether the Style panel is disabled entirely (waffle)
toolbar.isDisabled - — Enables Statistics/Show value in legend (waffle only)
legend.defaultLegendStats - — Hides the Nested toggle (waffle)
legend.hideNestedLegendSwitch - — Default legend visibility behavior for Auto mode
legend.getShowLegendDefault - — Maximum Group by dimensions
maxBuckets
读取 ,了解 Style 面板的结构:
toolbar/style_settings.tsx- 如果存在 → 渲染 Appearance 折叠面板 + Titles and text 折叠面板
emptySizeRatioOptions - 如果不存在 → 仅直接渲染 (无子标题)
PartitionTitlesAndTextSettings
然后读取 :
toolbar/titles_and_text_settings.tsx- 渲染为第一个按钮组(标签:检查 i18n 键
categoryOptions)xpack.lens.pieChart.labelSliceLabels - 渲染为第二个按钮组(标签:检查 i18n 键
numberOptions)xpack.lens.pieChart.sliceValues - 如果 ,则会出现 Decimal places 输入框
numberDisplay === 'percent'
如果 为空,则隐藏第一个按钮组。如果 为空,则隐藏第二个按钮组。如果 为 true,则整个部分会被禁用或隐藏。
categoryOptionsnumberOptionsisDisabledStep 2: Trace the Style settings
第 3 步:追踪 Legend 设置
Read to understand the Style panel structure:
toolbar/style_settings.tsx- If exists → renders Appearance accordion + Titles and text accordion
emptySizeRatioOptions - If not → renders only directly (no sub-headers)
PartitionTitlesAndTextSettings
Then read :
toolbar/titles_and_text_settings.tsx- renders as the first button group (label: check i18n key
categoryOptions)xpack.lens.pieChart.labelSliceLabels - renders as the second button group (label: check i18n key
numberOptions)xpack.lens.pieChart.sliceValues - If , a Decimal places input appears
numberDisplay === 'percent'
If is empty, the first button group is hidden. If is empty, the second button group is hidden. If is true, the entire section is disabled/hidden.
categoryOptionsnumberOptionsisDisabled读取 (分区图表包装器),查看传递给共享 组件的 props。需要检查的关键 props:
toolbar/legend_settings.tsxLegendSettings| Prop | 作用 | 验证方式 |
|---|---|---|
| 可见性选项(Auto/Show/Hide) | 所有分区图表始终存在 |
| 仅在同时传入 | 分区图表不传入 |
| Nested 开关 | |
| Statistics/Show value | 仅当图表元数据中定义了 |
| Width 下拉菜单 | 当 |
| Label truncation 开关 | Legend 未隐藏时始终存在 |
| 尺寸下拉菜单中的 Auto | 仅用于 8.3 之前的可视化 |
Step 3: Trace the Legend settings
第 4 步:确定渲染顺序
Read (partition wrapper) to see what props are passed to the shared component. Key props to check:
toolbar/legend_settings.tsxLegendSettings| Prop | What it controls | How to verify |
|---|---|---|
| Visibility options (Auto/Show/Hide) | Always present for all partition charts |
| Only renders if | Partition charts do NOT pass |
| Nested toggle | |
| Statistics/Show value | Only if |
| Width dropdown | Renders if |
| Label truncation toggle | Always present when legend not hidden |
| Auto in size dropdown | Only for pre-8.3 visualizations |
从头到尾读取共享的 JSX。对于分区图表(无 prop),实际渲染顺序为:
legend_settings.tsxlocation- Visibility(始终显示)
- Width(Legend 未隐藏时,通过 LegendSizeSettings 渲染)
- Label truncation + Line limit(Legend 未隐藏时)
- Nested(Legend 未隐藏、有多个组且未设置 时)
hideNestedLegendSwitch
不会为分区图表渲染的设置:
- Position——需要 prop(只有 XY 图表传入)
location - Statistics——要求
allowedLegendStats.length > 1 - Show value——要求恰好有 1 个类型为 Value/CurrentAndLastValue 的允许 Legend 统计项
Step 4: Determine rendering order
第 5 步:验证选项标签
Read the shared JSX top to bottom. For partition charts (no prop), the actual rendering order is:
legend_settings.tsxlocation- Visibility (always)
- Width (when legend not hidden, via LegendSizeSettings)
- Label truncation + Line limit (when legend not hidden)
- Nested (when legend not hidden AND multiple groups AND not hideNestedLegendSwitch)
Settings that do NOT render for partition charts:
- Position — requires prop (only XY charts pass this)
location - Statistics — requires
allowedLegendStats.length > 1 - Show value — requires exactly 1 allowed legend stat of type Value/CurrentAndLastValue
对于每个按钮组或下拉菜单,检查选项数组中的 或 。常见误区:
labelinputDisplay| 你可能以为 | 实际 UI 标签 | 来源 |
|---|---|---|
| "Labels" | "Slice labels" | |
| "Values" | "Slice values" | |
| "Legend size" | "Width" | |
| "Truncate" | "Label truncation" | |
| "Max lines" | "Line limit" | |
| "Show"(Legend) | "Show" | |
Step 5: Verify option labels
快速参考:各图表之间的差异
For each button group or dropdown, check the or in the options array. Common pitfalls:
labelinputDisplay| What you might assume | Actual UI label | Source |
|---|---|---|
| "Labels" | "Slice labels" | |
| "Values" | "Slice values" | |
| "Legend size" | "Width" | |
| "Truncate" | "Label truncation" | |
| "Max lines" | "Line limit" | |
| "Show" (legend) | "Show" | |
| 功能 | Pie/Donut | Treemap | Mosaic | Waffle |
|---|---|---|---|---|
| Slice labels | Hide/Inside/Auto | Hide/Show | (无) | (无) |
| Slice values | Hide/Integer/Percentage | Hide/Integer/Percentage | Hide/Integer/Percentage | (无) |
| Donut hole | 是 | 否 | 否 | 否 |
| Style 面板被禁用 | 否 | 否 | 否 | 是 |
| Legend Position | 否 | 否 | 否 | 否 |
| Legend Width | 是 | 是 | 是 | 是 |
| Nested legend | 是(>1 个组) | 是(>1 个组) | 是(>1 个组) | 否 |
| Show value | 否 | 否 | 否 | 是 |
| Statistics | 否 | 否 | 否 | 否 |
| Legend 默认可见性 | Auto 在 bucket > 1 时显示 | Auto 隐藏 | Auto 隐藏 | Auto 始终显示 |
| Group by 维度上限 | 3 | 2 | 2 | 1 |
| 颜色映射 | 仅第一个 Group by | 仅第一个 Group by | 垂直轴 | Group by |
Quick Reference: Per-Chart Differences
需要避免的常见错误
| Feature | Pie/Donut | Treemap | Mosaic | Waffle |
|---|---|---|---|---|
| Slice labels | Hide/Inside/Auto | Hide/Show | (none) | (none) |
| Slice values | Hide/Integer/Percentage | Hide/Integer/Percentage | Hide/Integer/Percentage | (none) |
| Donut hole | Yes | No | No | No |
| Style panel disabled | No | No | No | Yes |
| Legend Position | No | No | No | No |
| Legend Width | Yes | Yes | Yes | Yes |
| Nested legend | Yes (>1 group) | Yes (>1 group) | Yes (>1 group) | No |
| Show value | No | No | No | Yes |
| Statistics | No | No | No | No |
| Default legend visibility | Auto shows when >1 bucket | Auto hides | Auto hides | Auto shows always |
| Max Group by dimensions | 3 | 2 | 2 | 1 |
| Color mapping | First Group by only | First Group by only | Vertical axis | Group by |
- 误以为分区图表存在 Position——并不存在。只有 XY 类型的图表才有 Position。
- 使用 "Legend size" 而不是 "Width"——实际标签是 "Width"。
- 在 Width 选项中加入 Auto——Auto 只会在 8.3 之前的可视化中显示。
- 为非 waffle 图表记录 Statistics——只有 waffle 定义了 。
defaultLegendStats - 误以为所有图表都有 "Titles and text" 子标题——仅当定义了 时才会出现(pie/donut)。
emptySizeRatioOptions - 弄错 Nested legend 的条件——它要求 ,并且有多个 Group by 维度。
hideNestedLegendSwitch !== true - 误以为颜色映射适用于所有 Group by 层级——只有第一个维度可用。
Common Mistakes to Avoid
—
- Assuming Position exists for partition charts — it doesn't. Only XY-type charts have Position.
- Using "Legend size" instead of "Width" — the actual label is "Width".
- Including Auto in Width options — Auto only shows for pre-8.3 visualizations.
- Documenting Statistics for non-waffle charts — only waffle has .
defaultLegendStats - Assuming "Titles and text" sub-header exists for all charts — it only appears when is defined (pie/donut).
emptySizeRatioOptions - Getting the Nested legend condition wrong — it requires both AND multiple Group by dimensions.
hideNestedLegendSwitch !== true - Assuming color mapping works on all Group by levels — only available on the first dimension.
—