You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

能否将SandDance导出的Vega堆叠华夫图转换为Vega-Lite规范?

将SandDance Vega规范转换为Vega-Lite规范

核心实现逻辑

  • 采用row编码实现资源分组(对应原Vega的Department字段)
  • 通过color编码按工单状态着色(对应原Vega的Class字段)
  • 利用窗口转换计算分组内数据索引,自动排列方块的行列位置
  • 内置tooltip实现悬停查看工单详情

转换后的Vega-Lite规范

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {
    "url": "你的工单数据地址",
    "format": {"type": "tsv"} // 若为JSON数据,可改为{"type": "json"}
  },
  "transform": [
    // 计算分组内每个数据点的索引
    {
      "window": [{"op": "row_number", "as": "index"}],
      "groupby": ["resource"] // 替换为你的资源分组字段名
    },
    // 统计每个分组的总数据量
    {
      "joinaggregate": [{"op": "count", "as": "group_count"}],
      "groupby": ["resource"]
    },
    // 计算每行最多容纳的方块数(平方根向上取整)
    {"calculate": "ceil(sqrt(datum.group_count))", "as": "cols"},
    // 计算方块的行/列位置
    {"calculate": "floor((datum.index - 1) / datum.cols)", "as": "row_pos"},
    {"calculate": "(datum.index - 1) % datum.cols", "as": "col_pos"}
  ],
  "encoding": {
    "row": {
      "field": "resource",
      "type": "nominal",
      "title": "资源分组",
      "header": {"labelAngle": 0, "labelAlign": "right"}
    }
  },
  "spec": {
    "mark": {
      "type": "rect",
      "tooltip": true
    },
    "encoding": {
      "x": {
        "field": "col_pos",
        "type": "ordinal",
        "title": "",
        "axis": {"labels": false, "ticks": false, "domain": false}
      },
      "y": {
        "field": "row_pos",
        "type": "ordinal",
        "title": "",
        "axis": {"labels": false, "ticks": false, "domain": false}
      },
      "color": {
        "field": "status",
        "type": "nominal",
        "title": "工单状态",
        "scale": {"scheme": "category10"} // 可自定义状态颜色数组
      },
      "tooltip": [
        {"field": "resource", "title": "所属资源"},
        {"field": "status", "title": "工单状态"},
        {"field": "ticket_id", "title": "工单编号"},
        {"field": "overdue_days", "title": "逾期天数"} // 替换为你需要的详情字段
      ]
    },
    "config": {
      "view": {"stroke": "transparent"},
      "header": {"titleFontSize": 14, "labelFontSize": 12},
      "legend": {"titleFontSize": 14, "labelFontSize": 12}
    }
  }
}

工单场景适配说明

  1. 数据源替换:将data.url改为你的工单数据接口或本地文件路径,同步调整format.type适配数据格式
  2. 字段映射:把resource替换为你的资源分组字段名,status替换为工单状态字段(如逾期/延期/完成/取消)
  3. 详情自定义:修改tooltip内的字段列表,添加你需要展示的工单信息(如创建时间、处理人等)
  4. 颜色定制:若要指定状态对应颜色,将color.scale.scheme改为range数组,例如"range": ["#ff4d4f", "#faad14", "#52c41a", "#d9d9d9"]

内容的提问来源于stack exchange,提问作者APB Reports

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 18:37:03