4

I have code for stacked bar chart, got from Using Vega Lite to display already-aggregated data it works in vega editor

{
  "data": {
    "values": [
      {"bin": "[-inf,8.0)", "bad_distr": 0.009210526315789473, "good_distr": 0.07763157894736843},
      {"bin": "[8.0,14.0)", "bad_distr": 0.075, "good_distr": 0.21842105263157896},
      {"bin": "[14.0,16.0)", "bad_distr": 0.009210526315789473, "good_distr": 0.05394736842105263},
      {"bin": "[16.0,44.0)", "bad_distr": 0.16052631578947368, "good_distr": 0.3236842105263158},
      {"bin": "[44.0,inf)", "bad_distr": 0.04078947368421053, "good_distr": 0.031578947368421054}
    ]
  },
  "transform": [
    {"fold": ["bad_distr", "good_distr"], "as": ["bad", "good"]}
  ],
  "mark": {"type": "bar"},
  "encoding": {
    "y": {"type": "ordinal", "field": "bin"},
    "x": {"type": "quantitative", "field": "good"},
    "color": {"type": "nominal", "field": "bad"}
  }
}

Plot comes out good

enter image description here

Same data, I have in elastic database,

enter image description here

same code is throwing warning and plot not coming up

enter image description here

{
  "$schema": "https://vega.github.io/schema/vega-lite/v2.4.json",
  "title": {
    "text":  "Bin Plot",
    "fontSize":14
  },
  "data": {
    "url" : {
        "index": "scorecard_bin_plot",
        "body": {
          "size":10000,
          "_source": ["bin","good_distr","bad_distr"]
        }
      }  
      "format": {"property": "hits.hits"},
  },
  "transform": [
    {"fold": ["_source.bad_distr", "_source.good_distr"], "as": ["bad", "good"]}
  ],
  "mark": {"type": "bar"},
  "encoding": {
    "y": {"type": "ordinal", "field": "_source.bin"},
    "x": {"type": "quantitative", "field": "good"},
    "color": {"type": "nominal", "field": "bad"}
  }
}

I don't understand the issue

Using elastic and kibana 7.12.0

hanzgs
  • 1,498
  • 17
  • 44

1 Answers1

0

When using Vega, not Lite, with data from Elastic instead of hardcoded, it seems that in the transform functions the new field should be called "data" and get the data from the field in the format function. Like:

"format": {"property": "data_from_elastic"},
"transform": [{"type": "someType", "field":"data"}]

Maybe you can use _source in "property", call it data, and below use it as data.good_distr and data.bad_distr.

DMinovski
  • 61
  • 2
  • 2
  • 7