Vega stacked bar plot group by

Hi
I have an an scripted field "TotalCapacity" which return string "Error" or "OK". I want to count how many of "Error" and "Ok" i have in different timestamp. I have many returns of "TotalCapacity" for one vehicle so i want to group by "vehicleid" i know that this is posible in VEGA but i dont know how to do it.

I want something like on pic, but grouped by "vehicle id"


This is my Vega code but does not work:

{
$schema: https://vega.github.io/schema/vega-lite/v2.json
data: {
 url: {
  %timefield%: @timestamp
  %context%: true
  index: rti-warnings*
  body: {
    size: 0
    aggs: {
      report: {
        date_histogram: {
          field: @timestamp
          interval: {%autointerval%: true}
		  }
        aggs: {
          Total: {
            cardinality: {field: "TotalCapacity"}
            }
          Vehicle: {
           cardinality: {field: "vehicleid"}
          }
        }
      }
    }
    
    
  }
}
format: {property: "aggregations.report.buckets"}
}
mark: bar
transform: [
{
  aggregate: [
    {op: "count", field: "Total", as: "Sum"}
  ]
  groupby: ["Vehicle.value"]
}
]
encoding: {
x: {field: "key", timeUnit: "date", type: "temporal", axis: {title: false} }
y: { field: "Sum", type: "quantitative" }
}
}

AstroSlazak,

Are you looking to do this solely in Vega-Lite? Or would doing this in Vega work for you? If you are good with Vega, I can help you out pretty easily there.

-Midas

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