Forum Discussion
Deneb Split By More Than One Field In X Axis
- 1 year ago
Hi JayWee
Sorry for the late responsre.
Here's a revised version of your Deneb Vega-Lite spec that demonstrates how to concatenate multiple fields into a single X-axis grouping:
***************************************************************
{
"data": {
"name": "dataset"
},
"transform": [
{
"fold": ["Sum of Value_01", "Sum of Value_02"],
"as": ["MT", "value"]
},
{
"calculate": "year(datum.Date) + '-' + month(datum.Date) + ' / ' + datum.Location + ' / ' + datum.Type",
"as": "X_Label"
}
],
"mark": "bar",
"encoding": {
"x": {
"field": "X_Label",
"type": "ordinal",
"axis": {"labelAngle": -45}
},
"y": {
"aggregate": "sum",
"field": "value",
"type": "quantitative"
},
"color": {
"field": "MT",
"type": "nominal"
},
"tooltip": [
{"field": "MT"},
{"field": "value", "type": "quantitative"},
{"field": "X_Label"}
]
}
}
***************************************************************Explanation:
The "calculate" step combines year/month, location, and type into one string (X_Label) for the X-axis.
The x encoding uses this combined field as an ordinal axis.
You can sort or format the string as needed for better visual alignment.
This won’t give you true nested headers like Tableau, but visually it will resemble it with clear separation and stacked bars per grouping.
If the above information is helpful, please give us Kudos and mark the response as Accepted as solution.
Best Regards,
Community Support Team _ C Srikanth.
Hi JayWee
Yes, you can split the X-axis into multiple fields in Deneb (Vega-Lite) by using a concatenated field (concat) or a facet-based approach.
Modify your x encoding to concatenate multiple fields, such as Date, Location, and Type.
*****************************************************************************
{
"data": {
"name": "dataset"
},
"transform": [
{
"fold": ["Sum of Value_01","Sum of Value_02"],
"as": ["MT","value"]
}
],
"layer": [
{
"mark": "bar",
"encoding": {
"x": {
"field": "Date",
"type": "temporal",
"timeUnit": "yearmonth"
},
"xOffset": {
"field": "Location",
"type": "nominal"
},
"column": {
"field": "Type",
"type": "nominal"
},
"y": {
"field": "value",
"type": "quantitative",
"stack": "normalize",
"aggregate": "sum"
},
"color": {
"field": "MT",
"type": "nominal"
}
}
}
]
}
*****************************************************************************
If the above information helps you, please give us a Kudos and marked the Accept as a solution.
Best Regards,
Community Support Team _ C Srikanth.
Hi Csrikanth,
Thanks for the rapid reply.
I've tried the code above and seems like Vega Lite doesn't like the "column" very much.
Any idea how to resolve this?
Thanks
Jay