Need help with Vega, my bar graph is not showing and i dont get why.
Whilst on the job,
I plan to manipulate "Align_Distance_To_Go_mm" to extract the counts of the number of its values within +/-300 and assign it to a new variable.
After which, i want to extract the global count of this "Align_Distance_To_Go_mm" and do a calculate to find the percentage of values within +/-300 classified by "Current_Platform_Name"
Pls help me see if my code can improve. Thanks
{
"$schema": "https://vega.github.io/schema/vega-lite/v2.json",
"data": {
"url": {
"%context%": true,
"%timefield%": "DateTime",
"index": "nsew*",
"body": {
"size": 10000,
"_source": [
"Current_Platform_Name",
"Align_Distance_To_Go_mm",
"Train_Type"
]
}
},
"format": {"property": "hits.hits"}
},
"transform": [
{
"filter": {
"field": "datum._source['Align_Distance_To_Go_mm']",
"range": [-300, 300]
}
},
{
"joinaggregate": [
{
"op": "count",
"field": "datum.Align_Distance_To_Go_mm",
"as": "count_all_Dist"
}
],
"groupby": ["Current_Platform_Name"]
},
{
"joinaggregate": [
{
"op": "count",
"field": "datum.Align_Distance_To_Go_mm",
"as": "count_within_Dist"
}
],
"groupby": ["Current_Platform_Name"]
},
{
"calculate": " (datum.count_within_Dist/datum.count_all_Dist)*100 ",
"as": "Percent_Compliance"
}
],
"layer": [
{
"mark": "bar",
"height": {"step": 5},
"encoding": {
"x": {
"field": "Percent_Compliance",
"type": "quantitative",
"axis": {"title": "Percent_Compliance"}
},
"y": {
"field": "_source.Current_Platform_Name",
"type": "nominal",
"axis": {"title": "Platform Name"}
},
"color": {
"field": "_source.Current_Platform_Name",
"type": "nominal",
"legend": {"title": "Platform Legend"}
},
"shape": {"field": "_source.Current_Platform_Name", "type": "nominal"}
}
}
]
}