Deneb (Vega-lite) - 排序轴

问题描述 投票:0回答:1

我正在尝试对 Y 轴进行排序,请参见下面的屏幕截图。 基本上,我想根据偶数率按降序对 Y 轴进行排序。数据结构如下: 主要模型>次要模型,主要模型显示次要模型的事件率之和。

我差不多把它排序了,但是,主要型号标签就消失了。 PBI 文件可以在 https://github.com/triCNguyen5/Test/blob/main/sortingAxisLabels.pbix

找到

任何帮助或想法表示赞赏。这只是数据的子集,完整数据集具有不同的主要模型和它们自己的次要模型。

enter image description here

powerbi visualization powerbi-desktop vega-lite deneb
1个回答
0
投票

enter image description here

{
  "data": {
    "name": "dataset"
  },
  "transform": [
    {
      "sort": [
        {
          "field": "EventRate",
          "order": "descending"
        }
      ],
      "window": [
        {
          "op": "rank",
          "as": "EventRateRank"
        }
      ],
      "groupby": [
        "model"
      ]
    },
    {
      "calculate": "format(datum.EventRateRank, '0') + '|' + datum.ui_label",
      "as": "minor_model"
    }
  ],
  "layer": [
    {
      "name": "Major Model Bar",
      "mark": {
        "type": "bar",
        "color": "#004D45",
        "height": 20,
        "tooltip": true
      },
      "encoding": {
        "y": {
          "field": "model",
          "type": "nominal",
          "title": "Fleet"
        },
        "x": {
          "field": "EventRate",
          "type": "quantitative",
          "aggregate": "sum"
        }
      }
    },
    {
      "name": "Major Model Event Rate Label",
      "mark": {
        "type": "text",
        "align": "left",
        "dx": 5,
        "baseline": "middle"
      },
      "encoding": {
        "y": {
          "field": "model",
          "type": "nominal"
        },
        "x": {
          "field": "EventRate",
          "type": "quantitative",
          "aggregate": "sum"
        },
        "text": {
          "field": "EventRate",
          "type": "quantitative",
          "aggregate": "sum"
        }
      }
    },
    {
      "name": "Minor Model Bar",
      "mark": {
        "type": "bar",
        "color": "#8FC319",
        "height": 15,
        "tooltip": true
      },
      "encoding": {
        "y": {
          "field": "minor_model",
          "type": "ordinal",
          "axis": {
            "labelExpr": "split(datum.label, '|')[1]==null?split(datum.label, '|')[0]:split(datum.label, '|')[1]"
          }
        },
        "x": {
          "field": "EventRate",
          "type": "quantitative",
          "title": "Event Rate"
        }
      }
    },
    {
      "name": "Minor Model Event Rate Label",
      "mark": {
        "type": "text",
        "align": "left",
        "dx": 5,
        "baseline": "middle"
      },
      "encoding": {
        "y": {
          "field": "minor_model",
          "type": "ordinal"
        },
        "x": {
          "field": "EventRate",
          "type": "quantitative"
        },
        "text": {
          "field": "EventRate",
          "type": "quantitative"
        }
      }
    }
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.