0

How to clear a chart when there is no data

I have a bar chart with a pulldown menu, which allows the user to select which data to chart. I use datasource() to populate the series with data whenever the pulldown menu is changed.

I have six options in the pulldown menu. All of my users have data for the first five options, but the sixth piece of data is optional for the users. To date, about 25% of my users actually have data to display for this sixth option. In the use case where the user does not have data for the sixth option, I need to clear the chart when that option is selected from the pulldown. Currently, the chart will continue to show whatever the last selection on the pulldown menu was, and it's confusing to see data when I expect no data. 

Is there a way to force the chart to clear its data? 

Here is a link to video to show how the chart works: https://nimb.ws/d93Xel

--Trudy Voorhees

 

1 comment

  • Avatar
    Parker Selman Official comment

    Hi Trudy, 

    Thanks for the post! 

    The reason you're seeing the old data persist in this chart is because you're likely using applied filters to filter your chart with the user input control selection, meaning when a value is selected that filters out all data, the chart goes into an error state. In cases like this, we typically recommend setting up some formula logic in the formula for the chart series where if the selected value in the drop-down has no matches, zero values are displayed. Without knowing the exact setup of your Klip, I can't provide a specific example for your case, but this would generally look like: 

    IF(COUNT(SELECT(@data, @data=$variable))>0,@series data, 0) 

    where @data is the data that is filtered against the user input control's $variable, and @series data is the data displayed on your series. 

    I hope this helps - if you have any further questions around this, let us know at support@klipfolio.com and we can take a closer look! 

    Parker

Please sign in to leave a comment.