Grouped bar chart in vega Kibana

Hello Everyone

I have a grouped bar chart which is plotted correctly in Vega online editor, but when I try the code in Kibana the graph is not plotted correctly.

The desired graph should be like
grouped bar chart

x- axis year grouped by month
y-axis - count of inc logged/ ticket(field)

Below is the snippet I am trying in Kibana vega visualization.

    {
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  
  "title": "count of incidents grouped by year & month",
  "data": [
    {
      "name": "table",
      url: {
      // Apply dashboard context filters when set
      %context%: true
      index: grpdata
       body: {
        _source: ["num","year","month","priority","ticket"]
      } 
   }
   format: { property: "hits.hits" }
    /*  "transform": [
          {"type": "filter", "expr": "( priority == 'All' ) ? priority != datum.priority : priority == datum.priority"}
      ] */
    }
  ],
  /* "signals": [
    {
      "name": "priority",
      "value": "All",
      "bind": {"input": "select", "options": ["All","p1", "p2", "p3", "p4"]}
    }
  ], */
  "scales": [
    {
      "name": "xscale",
      "type": "band",
      "domain": {"data": "table", "field": "_source.year"},
       "range": "width",
      "padding": 0.2
    },
    {
      "name": "yscale",
      "type": "linear",
      "domain": {"data": "table", "field": "_source.ticket"},
      "range": "height",
      "round": true,
      "zero": true,
      "nice": true
    },
    {
      "name": "color",
      "type": "ordinal",
      "domain": {"data": "table", "field": "_source.month"},
      "range": {"scheme": "category20"}
    }
  ],
  "axes": [
    {
      "orient": "left",
      "scale": "yscale",
      "tickSize": 0,
      "labelPadding": 4,
      "zindex": 1,
      "title": ["num of inc"]
    },
    {"orient": "bottom", "scale": "xscale", "title": ["year grouped by month"]}
  ],
  "marks": [
    {
      "type": "group",
      "from": {"facet": {"data": "table", "name": "facet", "groupby": "year"}},
      "encode": {"enter": {"x": {"scale": "xscale", "field": "year"}}},
      "signals": [{"name": "width", "update": "bandwidth('xscale')"}],
      "scales": [
        {
          "name": "pos",
          "type": "band",
          "range": "width",
          "domain": {"data": "facet", "field": "_source.month"}
        }
      ],
      "marks": [
        {
          "name": "bars",
          "from": {"data": "facet"},
          "type": "rect",
          "encode": {
            "enter": {
              "x": {"scale": "pos", "field": "_source.month"},
              "width": {"scale": "pos", "band": 1},
              "y": {"scale": "yscale", "field": "_source.ticket"},
              "y2": {"scale": "yscale", "value": 0},
              "fill": {"scale": "color", "field": "_source.month"}
            }
          }
        }
      ]
    }
  ]
}

Thank you.

Could you provide the spec? This would help look at the issue and also let us see the underlying data.

You're using a select signal, which Vega renders using a scrollbar by default. See this bug https://github.com/elastic/kibana/issues/77553 for a workaround, which is to use an exact pixel size instead of auto size

Hi @aaron-nimocks

sorry for the delay.
Below is the spec code.

{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"data": {
"name": "table",
"format": {
"property": "hits.hits"
},
"values": {
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 11,
"max_score": 0,
"hits": [
{
"_index": "grpdata",
"_type": "_doc",
"_id": "cB6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "jan",
"ticket": 10,
"year": 1885,
"priority": "p1"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "cR6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "feb",
"ticket": 17,
"year": 1885,
"priority": "p2"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "ch6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "mar",
"ticket": 20,
"year": 1885,
"priority": "p3"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "cx6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "apr",
"ticket": 15,
"year": 1885,
"priority": "p3"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "dB6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "jan",
"ticket": 27,
"year": 1990,
"priority": "p4"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "dR6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "feb",
"ticket": 32,
"year": 1990,
"priority": "p1"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "dh6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "mar",
"ticket": 11,
"year": 1990,
"priority": "p4"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "dx6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "apr",
"ticket": 28,
"year": 1990,
"priority": "p3"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "eB6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "jan",
"ticket": 16,
"year": 2000,
"priority": "p2"
}
},
{
"_index": "grpdata",
"_type": "_doc",
"_id": "eR6C9XYBnEfVCkKl1axb",
"_score": 0,
"_source": {
"month": "feb",
"ticket": 19,
"year": 2000,
"priority": "p2"
}
}
]
}
}
},
"transform": [
{
"calculate": "datum._source.year",
"as": "year"
},
{
"calculate": "datum._source.month",
"as": "month"
},
{
"calculate": "datum._source.priority",
"as": "priority"
},
{
"calculate": "datum._source.num",
"as": "num"
},
{
"calculate": "datum._source.ticket",
"as": "ticket"
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {
"data": "table",
"field": "_source.year"
},
"range": "width",
"padding": 0.2
},
{
"name": "yscale",
"type": "linear",
"domain": {
"data": "table",
"field": "_source.ticket"
},
"range": "height",
"round": true,
"zero": true,
"nice": true
},
{
"name": "color",
"type": "ordinal",
"domain": {
"data": "table",
"field": "_source.month"
},
"range": {
"scheme": "category20"
}
}
],
"axes": [
{
"orient": "left",
"scale": "yscale",
"tickSize": 0,
"labelPadding": 4,
"zindex": 1
},
{
"orient": "bottom",
"scale": "xscale"
}
],
"marks": [
{
"type": "group",
"from": {
"facet": {
"data": "table",
"name": "facet",
"groupby": "year"
}
},
"encode": {
"enter": {
"x": {
"scale": "xscale",
"field": "year"
}
}
},
"signals": [
{
"name": "width",
"update": "bandwidth('xscale')"
}
],
"scales": [
{
"name": "pos",
"type": "band",
"range": "width",
"domain": {
"data": "facet",
"field": "_source.month"
}
}
],
"marks": [
{
"name": "bars",
"from": {
"data": "facet"
},
"type": "rect",
"encode": {
"enter": {
"x": {
"scale": "pos",
"field": "_source.month"
},
"width": {
"scale": "pos",
"band": 1
},
"y": {
"scale": "yscale",
"field": "_source.ticket"
},
"y2": {
"scale": "yscale",
"value": 0
},
"fill": {
"scale": "color",
"field": "_source.month"
}
}
}
},
{
"type": "text",
"from": {
"data": "bars"
},
"encode": {
"enter": {
"y": {
"field": "y2",
"offset": -5
},
"x": {
"field": "x",
"offset": {
"field": "width",
"mult": 0.5
}
},
"fill": [
{
"test": "contrast('white', datum.fill) > contrast('black', datum.fill)",
"value": "white"
},
{
"value": "black"
}
],
"align": {
"value": "right"
},
"baseline": {
"value": "middle"
},
"text": {
"field": "datum.value"
}
}
}
}
]
}
],
"config": {
"range": {
"category": {
"scheme": "elastic"
}
},
"arc": {
"fill": "#54B399"
},
"area": {
"fill": "#54B399"
},
"line": {
"stroke": "#54B399"
},
"path": {
"stroke": "#54B399"
},
"rect": {
"fill": "#54B399"
},
"rule": {
"stroke": "#54B399"
},
"shape": {
"stroke": "#54B399"
},
"symbol": {
"fill": "#54B399"
},
"trail": {
"fill": "#54B399"
},
"title": {
"color": "#343741"
},
"style": {
"guide-label": {
"fill": "#69707d"
},
"guide-title": {
"fill": "#343741"
},
"group-title": {
"fill": "#343741"
},
"group-subtitle": {
"fill": "#343741"
}
},
"axis": {
"tickColor": "#eef0f3",
"domainColor": "#eef0f3",
"gridColor": "#eef0f3"
},
"background": "transparent"
},
"width": "container",
"height": "container",
"autosize": {
"type": "fit",
"contains": "padding"
}
}

The above code is populating the graph with max values, instead of all the values.

where as I need graph to plot all the values.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.