Forum Discussion

JayWee's avatar
JayWee
Frequent Visitor
1 year ago
Solved

Deneb Split By More Than One Field In X Axis

Morning All,   Can i please find out whether is there a way to split X axis into more than one field? I can achieve this pretty easily withTableau, however with my current Deneb knowledge, i'm str...
  • v-csrikanth's avatar
    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.