例如,您可以将订单数量值可视化为线条,将用户年龄值可视化为列,以便在用户年龄在 y 轴上绘制后将其与其他值区分开来。
在 LookML 中创建测量
如果您日后打算再次在 y 轴上绘制特定维度,更可持续的做法是在 LookML 中创建 sum 测量值或 number 测量值,将您要绘制的维度转换为测量值。您可以从字段选择器中将该字段添加到查询中,而不必在“探索”中多次重新创建相同的表格计算。
该测量结果将如下所示:
measure: measure_for_age { ## replace with a new name
description: "Use this age field for displaying age on the y-axis"
type: number ## or sum
sql: ${age} ;; ## replace with your dimension
}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-31。"],[],[],null,["# How to plot dimensions on a Y-axis\n\n\u003e *All user data presented on this page is made up for example purposes.*\n\n\nLooker visualizations automatically determine which values to plot on a y-axis\nbased on what field types are present in a query. For example, if an Explore\nthat breaks down **Users First Name** and **Users Age** for\nthe top 10 highest **Orders Count** is visualized as a column chart,\nthe 10 dimension values for **Users First Name** and **Users Age**\nare automatically concatenated and separated by a dash (--) on the x-axis.\n\n\nWhat if you want to separate **Users Age** and **Users First Name** so that **Users Age** is\nplotted on the y-axis, and **Users First Name** and **Orders Count** appear on the x-axis?\n\n\nThe two following solutions outline how to transform a dimension, such as **Users Age**, into a measure so that it can be visualized on the y-axis:\n\n- [Using a table calculation](#using_a_table_calculation) --- Create a one-off solution directly from an Explore without developing LookML.\n- [Creating a measure](#creating_a_measure_in_lookml) --- Develop LookML to be able to reuse an expression in future Explores without needing to create a table calculation.\n\n\u003cbr /\u003e\n\nUsing a table calculation\n-------------------------\n\n\nA [table calculation](/looker/docs/table-calculations) is the fastest and easiest way to plot a dimension on the y-axis. A calculation is typically plotted as a dimension if no measures are involved in the expression. You can make a table calculation behave as a measure by including a measure in the calculation's expression. The key is making sure the measure won't affect the value of the original dimension.\n\nTo use a table calculation to plot a measure on the y-axis, perform the following steps:\n\n1. If there is no measure in your Explore query, add any measure (such as a count), and then [hide](/looker/docs/creating-visualizations#specifying_lookml_fields_to_include_in_the_visualization) it from the visualization. If there is already a measure in your query that you want to include in the visualization, there's no need to hide it.\n2. Next, create a table calculation:\n - For a **numerical field** , the calculation will be as follows:\n\n \u003cbr /\u003e\n\n ```\n ${mydimension} + (0 * ${mymeasure})\n ```\n *The calculation preserves the original dimension value by multiplying the\n measure by 0.*\n - For a **string field** , the calculation will involve two [logical functions,](/looker/docs/functions-and-operators#logical_functions,_operators,_and_constants) `if()` and `is_null()`, instead: \n\n ```\n if(is_null(${mymeasure}),${string_dimension},${string_dimension})\n ```\n This expression tells Looker to *always* display the value of the string dimension in place of the measure values.\n3. Hide the original dimension --- **Users Age** in this case --- from the visualization, since the table calculation --- **Age** measure --- now represents the dimension's values in the visualization.\n\n\nTo distinguish between values in a visualization --- in this example, the **Age** measure table calculation and **Orders Count** measures --- you can use [multiple vis types](/looker/docs/creating-visualizations#including_multiple_visualization_types_on_a_single_chart) in a single chart.\n\n\nFor example, you can visualize **Orders Count** values as a line and **Users Age** values as\na column to distinguish them once **Users Age** is plotted on the y-axis.\n\n\nCreating a measure in LookML\n----------------------------\n\n\nIf you plan to plot a specific dimension on a y-axis again in the future, a more sustainable option is to create a\n[`sum` measure](/looker/docs/reference/param-measure-types#sum) or [`number` measure](/looker/docs/reference/param-measure-types#sum)\nin LookML that makes the dimension you want to plot into a measure. Instead of recreating the same table calculation in an Explore multiple times, you can add the field to a query from the field picker.\n\nThe measure will look similar to this: \n\n```\n measure: measure_for_age { ## replace with a new name\n description: \"Use this age field for displaying age on the y-axis\"\n type: number ## or sum\n sql: ${age} ;; ## replace with your dimension\n }\n```\n\u003e *Adding a [`description`](/looker/docs/reference/param-field-description) to the measure can help users understand the intended use of a field.*\n\n\nIn this case, `measure_for_age` is a `number` type measure, since `number` type measures do not perform any actual aggregation. This means **Measure for Age** will display the same values as **Users Age** because it is a `number` type measure that does not perform any aggregation.\n\n\nOnce you create the measure, include both the dimension *and* the new measure in the Explore query. For this example, include the dimensions **Users First Name** and **Users Age** , and include the measures **Orders Count** and **Users Measure for Age**. Finally, hide the dimension that the measure is based on.\n\n\nWith the **Users Age** dimension hidden from the Explore visualization and [custom visualization settings applied](#custom_visualization), the resulting Explore visualization displays the **Users Measure for Age** on the y-axis and **Users First Name** on the x-axis, and the **Orders Count** values as a line."]]