{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"autosize":"none",
"height":"350",
"width":"300",
"padding":"30"
"title": {
"text": "Sample incident data",
"subtitle": "timeunit test",
"subtitleFontStyle": "italic",
"frame": "group",
"anchor": "start",
"offset": 10
},
"signals": [
{
"name": "timeunit", "value": ["day"],
"bind": {"input": "select", "options": [
["year"], ["month"], ["date"], ["day"], ["hours"]
]}
}
],
"data": [
{
"name": "incidents",
url: {
index: samptuint
body: {
_source: ["date", "ticket", "priority", "inc_num", "status"]
}
format: { property: "hits.hits" }
"transform": [
{
"type": "timeunit",
"field": "date",
"units": {"signal": "timeunit"},
"signal": "tbin"
},
{
"type": "aggregate",
"ops": ["count"],
"fields": ["inc"],
"as": ["inc"],
"groupby":["unit0"]
}
]
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"range": "width",
"padding": 0.05,
"round": true,
"domain": {"signal": "timeSequence(tbin.unit, tbin.start, tbin.stop)"}
},
{
"name": "yscale",
"type": "linear",
"range": "height",
"domain": {"data": "incidents", "field": "inc"},
"zero": true,
"nice": true
}
],
"axes": [
{ "orient": "bottom", "scale": "xscale",
"formatType": "time", "format": {"signal": "timeUnitSpecifier(tbin.units, {hours: '%H'})"} },
{ "orient": "left", "scale": "yscale" }
],
"marks": [
{
"type": "rect",
"from": {"data": "incidents"},
"encode": {
"update": {
"x": {"scale": "xscale", "field":"unit0"},
"width": {"scale": "xscale", "band": 1},
"y": {"scale": "yscale", "field": "inc"},
"y2": {"scale": "yscale", "value": 0},
"tooltip": {"signal": "{timeunit: timeFormat(datum.unit0, timeUnitSpecifier(tbin.units)), inc_count: format(datum.inc, ',')}"}
},
"hover": {
"fill": {"value": "firebrick"}
}
}
}
]
}
Response in spec(vega debug)
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"description": "A bar chart of flight statistics, aggregated by the selected time unit.",
"autosize": {
"type": "none",
"contains": "padding"
},
"height": "350",
"width": "300",
"padding": "30",
"title": {
"text": "Sample incident data",
"subtitle": "timeunit test",
"subtitleFontStyle": "italic",
"frame": "group",
"anchor": "start",
"offset": 10
},
"signals": [
{
"name": "timeunit",
"value": [
"day"
],
"bind": {
"input": "select",
"options": [
[
"year"
],
[
"month"
],
[
"date"
],
[
"day"
],
[
"hours"
]
]
}
}
],
"data": [
{
"name": "incidents",
"format": {
"property": "hits.hits"
},
"transform": [
{
"type": "timeunit",
"field": "date",
"units": {
"signal": "timeunit"
},
"signal": "tbin"
},
{
"type": "aggregate",
"ops": [
"count"
],
"fields": [
"inc"
],
"as": [
"inc"
],
"groupby": [
"unit0"
]
}
],
"url": {
"index": "samptuint",
"body": {
"_source": [
"date",
"ticket",
"priority",
"inc_num",
"status"
]
}
},
"values": {
"took": 0,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 14,
"max_score": 1,
"hits": [
{
"_index": "samptuint",
"_type": "_doc",
"_id": "ue3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "01-01-2012 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "uu3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "03-22-2012 20:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "u-3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "02-01-2012 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "vO3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "04-02-2012 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "ve3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "04-13-2012 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "vu3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "01-04-2018 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "v-3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "04-21-2016 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "wO3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "02-02-2016 23:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "we3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "03-03-2016 20:00:00"
},
"unit0": null,
"unit1": null
},
{
"_index": "samptuint",
"_type": "_doc",
"_id": "wu3lR3cBmDhuxKMfAKQP",
"_score": 1,
"_source": {
"date": "01-01-2018 23:00:00"
},
"unit0": null,
"unit1": null
}
]
}
}
}
],
"scales": [
{
"name": "xscale",
"type": "band",
"range": "width",
"padding": 0.05,
"round": true,
"domain": {
"signal": "timeSequence(tbin.unit, tbin.start, tbin.stop)"
}
},
{
"name": "yscale",
"type": "linear",
"range": "height",
"domain": {
"data": "incidents",
"field": "inc"
},
"zero": true,
"nice": true
}
],
"axes": [
{
"orient": "bottom",
"scale": "xscale",
"formatType": "time",
"format": {
"signal": "timeUnitSpecifier(tbin.units, {hours: '%H'})"
}
},
{
"orient": "left",
"scale": "yscale"
}
],
"marks": [
{
"type": "rect",
"from": {
"data": "incidents"
},
"encode": {
"update": {
"x": {
"scale": "xscale",
"field": "unit0"
},
"width": {
"scale": "xscale",
"band": 1
},
"y": {
"scale": "yscale",
"field": "inc"
},
"y2": {
"scale": "yscale",
"value": 0
},
"tooltip": {
"signal": "{timeunit: timeFormat(datum.unit0, timeUnitSpecifier(tbin.units)), inc_count: format(datum.inc, ',')}"
}
},
"hover": {
"fill": {
"value": "firebrick"
}
}
}
}
],
"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"
}
}
Any suggestion will be welcome ..
Thanks in advance.