Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 是否可以使用vega/vega lite实现此聚合?_Json_Kibana_Aggregation_Vega Lite_Vega - Fatal编程技术网

Json 是否可以使用vega/vega lite实现此聚合?

Json 是否可以使用vega/vega lite实现此聚合?,json,kibana,aggregation,vega-lite,vega,Json,Kibana,Aggregation,Vega Lite,Vega,我有一个这种格式的数据列表 [ {"id": 100, "y": 28, "c":0}, {"id": 1, "y": 20, "c":1}, {"id": 2, "y": 43, "c":0}, {"id": 3, "y": 35, "

我有一个这种格式的数据列表

[
    {"id": 100, "y": 28, "c":0},
    {"id": 1, "y": 20, "c":1},
    {"id": 2, "y": 43, "c":0},
    {"id": 3, "y": 35, "c":1},
    {"id": 4, "y": 81, "c":0},
    {"id": 5, "y": 10, "c":1},
    {"id": 6, "y": 19, "c":0},
    {"id": 7, "y": 15, "c":1},
    {"id": 8, "y": 52, "c":0},
    {"id": 9, "y": 48, "c":1}
]
我的目标是为id=100以外的所有文档实现x和y字段的总和聚合,然后从id=100的文档的x和y值中减去此聚合结果,并将此结果显示为文本类型标记。 我尝试了以下方法:

{
  $schema: https://vega.github.io/schema/vega/v3.0.json
  title: Sum amount Per id
  data: [
    {
      "name": "table",
      "values": [
    {"id": 100, "y": 28, "c":0},
    {"id": 1, "y": 20, "c":1},
    {"id": 2, "y": 43, "c":0},
    {"id": 3, "y": 35, "c":1},
    {"id": 4, "y": 81, "c":0},
    {"id": 5, "y": 10, "c":1},
    {"id": 6, "y": 19, "c":0},
    {"id": 7, "y": 15, "c":1},
    {"id": 8, "y": 52, "c":0},
    {"id": 9, "y": 48, "c":1}
]
      transform: [
        {
          type: aggregate
          ops: ["sum","sum"]
          fields: ["c", "y"]
          as: ["sumc","sumy"]
        }
        
      ]
    }
  ]
  marks: [
    {
      type: text
      from: {data: "table"}
      encode: {
        update: {
          text: {signal: "datum.sumc"}
          align: {value: "center"}
          baseline: {value: "middle"}
          xc: {signal: "width/4"}
          yc: {signal: "height/2"}
          fontSize: {signal: "min(width/10, height)/1.3"}
        }
      }
    }
    {
      type: text
      from: {data: "table"}
      encode: {
        update: {
          text: {signal: "datum.sumy"}
          align: {value: "center"}
          baseline: {value: "middle"}
          xc: {signal: "width*3/4"}
          yc: {signal: "height/2"}
          fontSize: {signal: "min(width/10, height)/1.3"}
        }
      }
    }
  ]
}


请帮助我如何实现id=100的减法,我能够使用Vega的JoinAggregate转换解决这个问题,方法是将聚合值作为附加列添加到数据集中,然后过滤以获得具有所需值的单行

{
  "$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "title": "Sum amount Per id",
  "data": [
    {
      "name": "table",
      "values": [
        {"id": 100, "y": 2800, "c": 1000},
        {"id": 1, "y": 20, "c": 1},
        {"id": 2, "y": 43, "c": 0},
        {"id": 3, "y": 35, "c": 1},
        {"id": 4, "y": 81, "c": 0},
        {"id": 5, "y": 10, "c": 1},
        {"id": 6, "y": 19, "c": 0},
        {"id": 7, "y": 15, "c": 1},
        {"id": 8, "y": 52, "c": 0},
        {"id": 9, "y": 48, "c": 1}
      ],
      "transform": [
        {
          "type": "joinaggregate",
          "ops": ["sum", "sum"],
          "fields": ["c", "y"],
          "as": ["sumc", "sumy"]
        },{
        "type":"filter"
        "expr":"datum.id==100"
        }
      ]
    }
  ],
  "marks": [
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "update": {
          "text": {"signal": "-datum.sumc+datum.c*2"},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "xc": {"signal": "width/4"},
          "yc": {"signal": "height/2"},
          "fontSize": {"signal": "min(width/10, height)/1.3"}
        }
      }
    },
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "update": {
          "text": {"signal": "datum.y-datum.sumy+datum.y"},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "xc": {"signal": "width*3/4"},
          "yc": {"signal": "height/2"},
          "fontSize": {"signal": "min(width/10, height)/1.3"}
        }
      }
    }
  ]
}

我能够使用Vega的JoinAggregate转换解决这个问题,方法是将聚合值作为附加列添加到数据集中,然后过滤以获得具有所需值的单行

{
  "$schema": "https://vega.github.io/schema/vega/v3.0.json",
  "title": "Sum amount Per id",
  "data": [
    {
      "name": "table",
      "values": [
        {"id": 100, "y": 2800, "c": 1000},
        {"id": 1, "y": 20, "c": 1},
        {"id": 2, "y": 43, "c": 0},
        {"id": 3, "y": 35, "c": 1},
        {"id": 4, "y": 81, "c": 0},
        {"id": 5, "y": 10, "c": 1},
        {"id": 6, "y": 19, "c": 0},
        {"id": 7, "y": 15, "c": 1},
        {"id": 8, "y": 52, "c": 0},
        {"id": 9, "y": 48, "c": 1}
      ],
      "transform": [
        {
          "type": "joinaggregate",
          "ops": ["sum", "sum"],
          "fields": ["c", "y"],
          "as": ["sumc", "sumy"]
        },{
        "type":"filter"
        "expr":"datum.id==100"
        }
      ]
    }
  ],
  "marks": [
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "update": {
          "text": {"signal": "-datum.sumc+datum.c*2"},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "xc": {"signal": "width/4"},
          "yc": {"signal": "height/2"},
          "fontSize": {"signal": "min(width/10, height)/1.3"}
        }
      }
    },
    {
      "type": "text",
      "from": {"data": "table"},
      "encode": {
        "update": {
          "text": {"signal": "datum.y-datum.sumy+datum.y"},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "xc": {"signal": "width*3/4"},
          "yc": {"signal": "height/2"},
          "fontSize": {"signal": "min(width/10, height)/1.3"}
        }
      }
    }
  ]
}