Looker 圖表會根據查詢中顯示的欄位類型,自動判斷要在 y 軸上繪製哪些值。舉例來說,如果探索針對 Orders Count 前 10 大的值,以 Users First Name 和 Users Age 細分資料,並以直欄圖呈現,系統就會自動將 Users First Name 和 Users Age 的 10 個維度值連結,並在 x 軸上以破折號 (–) 分隔。
如果您想將「使用者年齡」和「使用者姓名」分開,以便將「使用者年齡」繪製在 y 軸上,而「使用者姓名」和「訂單數量」則顯示在 x 軸上,該怎麼做呢?
以下兩種解決方案概述如何將維度 (例如「使用者年齡」) 轉換為評估資料,以便在 y 軸上進行視覺化:
舉例來說,您可以將「訂單數量」值設為線條,將「使用者年齡」值設為欄,藉此區分這兩個值,並在 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"]],["上次更新時間: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."]]