Using stacked bar charts

I have data in JSON format like this in my elasticsearch:

{
    "features": [
          {
            "feature": "A",
            "Yes": 19,
            "No": 0,
            "Maybe": 81
          },
          {
            "feature": "B",
            "Yes": 0,
            "No": 0,
            "Maybe": 100
          },
          {
            "feature": "C",
            "Yes": 10,
            "No": 32,
            "Maybe": 58
          }
        ]
    }

From this, is it possible to obtain a stacked chart as follows?
image

Hi,

Unfortunately, that data format is a nested datatype, which isn't supported in Kibana right now.

Regardless, since Kibana uses aggregations to visualize data, you will have to store the data as separate documents, such as:

POST /stackedtest/doc
{
  "feature": "A",
  "response": "Yes",
  "count": 19
}
POST /stackedtest/doc
{
  "feature": "A",
  "response": "No",
  "count": 0
}
POST /stackedtest/doc
{
  "feature": "A",
  "response": "Maybe",
  "count": 81
}
POST /stackedtest/doc
{
  "feature": "B",
  "response": "Yes",
  "count": 0
}
POST /stackedtest/doc
{
  "feature": "B",
  "response": "No",
  "count": 0
}
POST /stackedtest/doc
{
  "feature": "B",
  "response": "Maybe",
  "count": 100
}
POST /stackedtest/doc
{
  "feature": "C",
  "response": "Yes",
  "count": 10
}
POST /stackedtest/doc
{
  "feature": "C",
  "response": "No",
  "count": 32
}
POST /stackedtest/doc
{
  "feature": "C",
  "response": "Maybe",
  "count": 58
}

Then you can build a stacked bar where the X-Axis is a filters aggregation, the Y-Axis is split using a terms aggregation of the response, and the Y-Axis metric is a max of the response count for the term:

2 Likes

This was very helpul! Thanks a lot :slight_smile:

1 Like

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