{ "$schema": "https://vega.github.io/schema/vega/v5.json", "description": "Bar Chart with a spacing-saving y-axis", "background": "white", "padding": 5, "width": 200, "style": "cell", "data": [ { "name": "source_0", "url": "data/cars.json", "format": {"type": "json"}, "transform": [ { "type": "aggregate", "groupby": ["Origin"], "ops": ["count"], "fields": [null], "as": ["__count"] } ] } ], "signals": [ {"name": "y_step", "value": 50}, {"name": "height", "update": "bandspace(domain('y').length, 0, 0) * y_step"} ], "marks": [ { "name": "marks", "type": "rect", "style": ["bar"], "from": {"data": "source_0"}, "encode": { "update": { "cornerRadiusTopRight": {"value": 2}, "cornerRadiusBottomRight": {"value": 2}, "fill": {"value": "#4c78a8"}, "ariaRoleDescription": {"value": "bar"}, "description": { "signal": "\"Number of Cars: \" + (format(datum[\"__count\"], \"\")) + \"; Origin: \" + (isValid(datum[\"Origin\"]) ? datum[\"Origin\"] : \"\"+datum[\"Origin\"])" }, "x": {"scale": "x", "field": "__count"}, "x2": {"scale": "x", "value": 0}, "y": {"scale": "y", "field": "Origin", "offset": 5, "band": 0.25}, "height": {"scale": "y", "band": 0.5} } } } ], "scales": [ { "name": "x", "type": "linear", "domain": {"data": "source_0", "field": "__count"}, "range": [0, {"signal": "width"}], "nice": true, "zero": true }, { "name": "y", "type": "band", "domain": {"data": "source_0", "field": "Origin", "sort": true}, "range": {"step": {"signal": "y_step"}}, "padding": 0 } ], "axes": [ { "scale": "y", "orient": "left", "bandPosition": 0, "grid": true, "gridScale": "x", "domain": false, "labels": false, "aria": false, "maxExtent": 0, "minExtent": 0, "ticks": false, "zindex": 0 }, { "scale": "x", "orient": "bottom", "grid": false, "title": "Number of Cars", "labelFlush": true, "labelOverlap": true, "tickCount": {"signal": "ceil(width/40)"}, "zindex": 0 }, { "scale": "y", "orient": "left", "grid": false, "title": "Origin", "bandPosition": 0, "domain": false, "labelAlign": "left", "labelBaseline": "middle", "labelOffset": -15, "labelPadding": -5, "ticks": false, "titleAlign": "left", "titleX": 5, "titleY": -5, "titleAngle": 0, "zindex": 0 } ] }