如何在Vega中访问嵌套的json

时间:2018-07-19 10:56:51

标签: kibana vega

我在基巴纳语中使用vega。我尝试访问嵌套的json字段,但无法访问该字段,任何人都可以帮助我解决此问题。我附上我的vega json,索引名称为pie

索引数据示例:

{   “ _index”:“派”,   “ _type”:“喇叭形”,   “ _id”:“ 2”,   “ _version”:1   “ _score”:1   “_资源”: {          “ id”:2         “父母”:1        “数据”:{        “内存”:50                }     }   }

{
 "$schema": "https://vega.github.io/schema/vega/v3.json",
 "data": [
{
  "name": "table",
  "url": {

  "%context%": "true",

  "index": "pie*",

  "body": {

    "size": "10000"


  }
},

"format": { "property": "hits.hits" },

"transform": [
    {
      "type": "formula",
      "expr": "toNumber(datum[\"_source\"][\"data\"][\"memory\"])",
      "as": "memory"
    }
          ],
  "transform": [{"type": "pie", "field": "memory"}]
  }  ],

      "scales": [
      {
  "name": "r",
  "type": "sqrt",
      "domain": {"data": "table", "field": "memory"},
  "zero": true,
  "range": [20, 100]
  }
     ],

  "marks": [
{
  "type": "arc",
  "from": {"data": "table"},
  "encode": {
    "enter": {
      "x": {"field": {"group": "width"}, "mult": 0.5},
      "y": {"field": {"group": "height"}, "mult": 0.5},
      "startAngle": {"field": "startAngle"},
      "endAngle": {"field": "endAngle"},
      "innerRadius": {"value": 20},
      "outerRadius": {"scale": "r", "field": "memory"},
      "stroke": {"value": "#fff"}
    },
    "update": {
      "fill": {"value": "#ccc"}
    },
    "hover": {
      "fill": {"value": "skyblue"}
    }
  }
       },

    {
  "type": "text",
  "from": {"data": "table"},
  "encode": {
    "enter": {
      "x": {"field": {"group": "width"}, "mult": 0.5},
      "y": {"field": {"group": "height"}, "mult": 0.5},
      "radius": {"scale": "r", "field": "memory", "offset": 8},
      "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"},
      "fill": {"value": "#000"},
      "align": {"value": "center"},
      "baseline": {"value": "middle"},
      "text": {"field": "memory"}
    }
  }
}
  ]   
    }

1 个答案:

答案 0 :(得分:0)

此问题已在https://github.com/vega/vega/issues/1371

中回答

您已经在数据变量中定义了"format": { "property": "hits.hits" },但在数据中看不到。 即使是这样,以我的理解,property也不接受双嵌套参数(例如varx.vary),但为此我可能是错的。

接下来,您在一个transform规范中有两个data定义。

更改此内容,将给我: enter image description here

{
  "$schema": "https://vega.github.io/schema/vega/v4.json",
  "data": [
    {
      "name": "table",
      "values": [
        {
          "_index": "pie",
          "_type": "flare",
          "_id": "2",
          "_version": 1,
          "_score": 1,
          "_source": {"id": 2, "parent": 1, "data": {"memory": 50}}
        }
      ],
      "transform": [
        {
          "type": "formula",
          "expr": "toNumber(datum[\"_source\"][\"data\"][\"memory\"])",
          "as": "memory"
        },
        {"type": "pie", "field": "memory"}
      ]
    }
  ],
  "scales": [
    {
      "name": "r",
      "type": "sqrt",
      "domain": {"data": "table", "field": "memory"},
      "zero": true,
      "range": [20, 100]
    }
  ],
  "marks": [
    {
      "type": "arc",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"field": {"group": "width"}, "mult": 0.5},
          "y": {"field": {"group": "height"}, "mult": 0.5},
          "startAngle": {"field": "startAngle"},
          "endAngle": {"field": "endAngle"},
          "innerRadius": {"value": 20},
          "outerRadius": {"scale": "r", "field": "memory"},
          "stroke": {"value": "#fff"}
        },
        "update": {"fill": {"value": "#ccc"}},
        "hover": {"fill": {"value": "skyblue"}}
      }
    },
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"field": {"group": "width"}, "mult": 0.5},
          "y": {"field": {"group": "height"}, "mult": 0.5},
          "radius": {"scale": "r", "field": "memory", "offset": 8},
          "theta": {"signal": "(datum.startAngle + datum.endAngle)/2"},
          "fill": {"value": "#000"},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "text": {"field": "memory"}
        }
      }
    }
  ]
}