Hi There, I got a problem,
I am trying to create a chart with VEGA. I want in the x axis the time and in the y axis the number of doc_count. And ofcourse for coolnes i wanted the data in y-axis stacked by the continent_code.
The stacking creates a y0 and y1 for me, this works fine. But this y0 should start for a new point on the x from 0, but it is having an offset from the last point on x.
Let me show this in image1:
On the 6 elm in the table array there is a new date so the y0 should be 0 but it is taking the value from table[5].y1
And this follows that my chart looks a bit stupid. Let me show you that in image 2:
And this is my code :
{
"$schema": "https://vega.github.io/schema/vega/v3.json",
"padding": 5,
"data": [
{
"name": "table",
"url": {
"%context%": true,
"%timefield%": "@timestamp",
"index": "demo_logs_server*",
"body": {
"size": 0,
"aggs": {
"logs_time_country": {
"composite": {
"size": 50,
"sources": [
{
"time": {
"date_histogram": {
"field": "@timestamp",
"interval": {"%autointerval%":200},
"format": "dd-MM"
}
}
},
{
"country": {
"terms": {
"field": "geoip.continent_code.keyword"
}
}
}
]
}
}
}
}
},
"format": {
"property": "aggregations.logs_time_country.buckets"
},
"transform": [
{
"type": "stack",
"groupby": ["time"],
"sort": {"field":"country"},
"field": "doc_count"
}
]
}
],
"scales": [
{
"name": "x",
"type": "point",
"range": "width",
"domain": {"data": "table", "field": "key.time"}
},
{
"name": "y",
"type": "linear",
"range": "height",
"nice": true, "zero": true,
"domain": {"data": "table", "field": "y1"}
},
{
"name": "color",
"type": "ordinal",
"range": "category",
"domain": {"data": "table", "field": "key.country"}
}
],
"axes": [
{"orient": "bottom", "scale": "x", "zindex": 1},
{"orient": "left", "scale": "y", "zindex": 1}
],
"marks": [
{
"type": "group",
"from": {
"facet": {
"name": "series",
"data": "table",
"groupby": "key.country"
}
},
"marks": [
{
"type": "area",
"from": {"data": "series"},
"encode": {
"enter": {
"interpolate": {"value": "linear"},
"x": {"scale": "x", "field": "key.time"},
"y": {"scale": "y", "field": "y0"},
"y2": {"scale": "y", "field": "y1"},
"fill": {"scale": "color", "field": "key.country"}
},
"update": {
"fillOpacity": {"value": 1}
},
"hover": {
"fillOpacity": {"value": 0.5}
}
}
}
]
}
]
}
I think the mistake is somewhere in the transform-stack cause this is the part which is calculating the y0 and y1.
Will appriciate any kind of help
Thanks folks