Hi everyone,
I’m currently working in Workshop using Vega chart and facing a challenge.
I need to link a variable, which is updated by a button selection, to control the appearance of a line in my vega visualization. Specifically, I’m trying to make a line appear or disappear based on the value of this variable. Can anyone please help me?
The first, and its not specific to Vega, would be to make multiple charts, each with a different variation of what is visible, and then hide/show the single chart you want based on your variables using section conditional visibility. This is obviously a workaround, but one that has been used with some success.
The second, and it might not apply in your case, would be to use an object set filter. Depending on how your chart is set up and what variables it uses for data input, you could apply an object set filter variable to it, where that filter is controlled by a filter list or some other widget to conditionally show data.
The final Vega-specific option I can think of is to make your Vega spec function-backed. The Vega spec can be specified with a string variable, so you can use a variable that calls to a function to get your spec. Functions can take variable inputs, so you can pass through your variables and write logic in your function to include/exclude certain parts of your spec given those inputs.