az5112
az5112

Reputation: 642

How to prevent axis/domain adjustments during selection in Vega-lite

Here is my variation of the Vega-Lite Bike Counts with Dynamic Scale community example.

When a time span is selected in the middle chart, the bottom charts do on the fly aggregations (sum and quantiles). However, as I move the selection in the middle graph, some fruit may disappear; likewise the X axes keep adjusting. I would like both the fruit and the X axes in the bottom charts to 'freeze' after the chart is initially rendered.

What would be the best way to solve it directly in Vega-Lite?

Upvotes: 1

Views: 275

Answers (1)

joelostblom
joelostblom

Reputation: 48879

You can set a fixed domain of the y-axis to ensure that it does not change even when some fruits lack observations in the selected range:

"y": {
    "field": "fruit",
    "type": "nominal",
    "axis": {"title": ""}, 
    "scale": {"domain": ["apple", "banana", "lemon", "mango", "orange", "peach", "raspberry", "strawberry"]}
},

enter image description here

Open the Chart in the Vega Editor

Upvotes: 1

Related Questions