Vega charts in Workshop - how to make a line appear or disappear based on a button selection

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?

In alternative, is there another way for me to make this button selection → making line appear disappear in a chart without using vega?

I am very very stuck… thank you!

Hi! There are a couple options here.

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.

Let me know if any of these prove to be helpful!

Tim

2 Likes

Hi Tim,
Thank you for your answers! For now I found another solution by using the variable option inside vega. These are the steps:

  1. Create a string “variable transformation” and select if statement
  2. Choose as the output string, choose your boolean (in this case, my button boolean) and add your json in there when the line needs to appear
  3. In the else, add the json when the line doesn’t appear
  4. Add this string to the spec variable inside the vega chart

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.