Forum Discussion

HQ_Dev_Prod's avatar
HQ_Dev_Prod
Cloud Apps
09-17-2024
Solved

Line Chart - Show only with filter

I am building a line chart that shows value over time. However, there are over items. Is there a way to setup the line chart to only show when I filter on one item?

Example:

Line chart is blank > then I select one item from my drop down or filter > then the line chart will show it's value over time. 

  • Hi HQ_Dev_Prod ,

    You can achieve this by using a widget script. Add the script below to your line chart and ensure you update the variable 'filterTitle' with the name of your filter.

    This script will also display the message "Select one filter item" if no items or more than one item are selected. For further customization of the message and image, check out this post: https://www.binextlevel.com/post/custom-no-result-message

     

    const filterTitle = 'Category';
    
    widget.on('beforequery', function(w, args){
    	const dashFilter = prism.activeDashboard.filters.flatten().find(el => el.jaql.title === filterTitle);
    	
    	if(!dashFilter) {
    		return;
    	}
    	if(!(dashFilter.jaql.filter.members && dashFilter.jaql.filter.members.length === 1)) {
    		args.query.metadata.length = 0;
    	}
    })
    
    //To Customize message
    widget.on('domready', function(se){
    	const dashFilter = prism.activeDashboard.filters.flatten().find(el => el.jaql.title === filterTitle);
    	
    	if(!dashFilter) {
    		return;
    	}
    		
    	if(!(dashFilter.jaql.filter.members && dashFilter.jaql.filter.members.length === 1)) {
    		if (prism.activeWidget == null)
    			no_result_container = $(`widget[widgetid="${se.oid}"]`)
    		else
    			no_result_container = $('.prism-widget-preview')
    		
    		$(no_result_container).find('.widget-no-result-overlay .widget-no-result-notify-holder .no-result-title').text('Select one filter item')
    	}
    })

     

    Result:

    Feel free to reach out if you have any questions!

    -Hari

    https://www.binextlevel.com/ 

     

6 Replies

  • harikm007's avatar
    harikm007
    Data Warehouse

    Hi HQ_Dev_Prod ,

    You can achieve this by using a widget script. Add the script below to your line chart and ensure you update the variable 'filterTitle' with the name of your filter.

    This script will also display the message "Select one filter item" if no items or more than one item are selected. For further customization of the message and image, check out this post: https://www.binextlevel.com/post/custom-no-result-message

     

    const filterTitle = 'Category';
    
    widget.on('beforequery', function(w, args){
    	const dashFilter = prism.activeDashboard.filters.flatten().find(el => el.jaql.title === filterTitle);
    	
    	if(!dashFilter) {
    		return;
    	}
    	if(!(dashFilter.jaql.filter.members && dashFilter.jaql.filter.members.length === 1)) {
    		args.query.metadata.length = 0;
    	}
    })
    
    //To Customize message
    widget.on('domready', function(se){
    	const dashFilter = prism.activeDashboard.filters.flatten().find(el => el.jaql.title === filterTitle);
    	
    	if(!dashFilter) {
    		return;
    	}
    		
    	if(!(dashFilter.jaql.filter.members && dashFilter.jaql.filter.members.length === 1)) {
    		if (prism.activeWidget == null)
    			no_result_container = $(`widget[widgetid="${se.oid}"]`)
    		else
    			no_result_container = $('.prism-widget-preview')
    		
    		$(no_result_container).find('.widget-no-result-overlay .widget-no-result-notify-holder .no-result-title').text('Select one filter item')
    	}
    })

     

    Result:

    Feel free to reach out if you have any questions!

    -Hari

    https://www.binextlevel.com/ 

     

    • HQ_Dev_Prod's avatar
      HQ_Dev_Prod
      Cloud Apps

      Thank you Hari!

      Is it possible to set this process up so that if I select an item from a pie chart to filter the data, the line chart populates? Such that I don't have to go to the filters pan, but rather I can drill down to the line chart detail for a specific item from a pie chart? 

       

      • harikm007's avatar
        harikm007
        Data Warehouse

        If I understand your question correctly, you want the line chart to update when you click on a slice of the pie chart, right? If that's the case, clicking on a slice of the pie chart automatically applies a filter to the dashboard, so the same script should work here. Please refer to the GIF below.

         

         

        Does that address your question?