[{"id":"bcb0874d-299b-448e-9552-9e9b25ef80dd","tags":[{"product":null,"links":null,"id":"ba7e818e-4f6b-4211-b1ac-58e3bafcf439","name":"\u66F4\u65B0","color":"orange","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"8ce3627e-9e58-471b-9133-4f135d191e7b","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"ae60ae59-34f5-4f32-a8eb-243ed1457543","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"3d4848c3-910f-4ffa-9153-60bb507334a9","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"133f4ca6-d951-4d65-a618-3dc6301266f7","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"de62ec1c-813e-40b1-8160-a4cd109afe64","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2426c71d-8332-4cbd-a436-1ec4f8666464","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2ce7b6b0-78aa-4e4b-bf8a-e4ba2f988298","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"4706db46-0811-4652-8f59-1e0a1da84758","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"8f1271bb-2cd9-4f39-9897-c15b239ee7ab","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"677e13a7-6f3e-449f-986c-2c3a26f8d54f","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"5e40f6dc-caec-49d7-a1d0-be65f06815ba","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2457f0e0-9e71-4860-a87d-065e0fb84f84","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"d5c67fd0-1145-482c-9113-97b492c44c18","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"a609a8fa-ab91-4c1d-a1c3-d209d0463303","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"b4a9eb15-94e5-48df-b218-a24138f0cf9c","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]}]
        
(Showing Draft Content)

动态维度

需求描述

在同一图表中可以自由切换不同的维度查看同一度量值,而无需创建多个图表。如下图所示效果。

表达式-动态切换纬度示例.gif

在仪表板中实现

接下来为您介绍实现动态维度的步骤:

1. 首先添加一个标签列表,用来选择维度。

这里的数据来源我们使用手动添加的方法,添加“客户地区”、“客户省份”和“客户城市”三个维度。

image2022-5-6_16-31-20.png


2.选择模式调为单选

image2022-5-6_16-42-44.png


3. 添加一个仪表板参数,使其绑定刚才添加的标签列表。这个参数是实现动态切换的关键,后续会将标签列表选择的值传递到维度中。

image2022-5-6_16-48-47.png


并为参数设置一个默认值。

image2022-5-7_10-32-20.png


4. 添加柱形图,绑定数据集。然后在数据集上新建一个度量值,使用表达式计算出销售额。

image2022-5-6_17-34-56.png

image2022-5-6_17-37-10.png

新建一个数据列作为动态维度。

image2022-5-6_17-38-47.png

使用 Switch 函数,并引用仪表板参数1。

image2022-5-6_17-44-47.png


完成后,如下图所示。

含义为当仪表板参数1 值为“客户地区”时,动态维度为“客户地区”;当仪表板参数1 值为“客户省份”时,动态维度为“客户省份”;当仪表板参数1 值为“客户城市”时,动态维度为“客户城市”;当仪表板参数1 值为其他值时,动态维度为“客户地区”。

而仪表板参数1 的值来自于标签列表,所以最终维度会根据标签列表中选择的值发现变化。

image2022-5-6_17-41-54.png


5. 绑定数据。

image2022-5-6_17-49-6.png


6. 预览数据,发现已经实现了维度的自由切换效果。

image2022-5-6_17-57-44.png


7. 另外,还可以使用富文本组件添加一个动态标题。关键点在于富文本中绑定仪表板参数1。这样随着仪表板参数的变化,显示的标题也会随之而变。

image2022-5-7_11-15-59.png


8. 为了更加统一,我们将标签列表筛选器的默认值也设置为仪表板参数1。因为参数有默认值,所以默认会选中客户地区。

image2022-5-7_11-36-29.png


9. 此时预览即可达到示例效果。自由切换不同的维度查看同一度量值。

image2022-5-7_11-39-49.png