Forum Discussion

Lisha's avatar
Lisha
Cloud Apps
09-02-2022
Solved

Widget script for specific condition in Column chart

Below is a script that I had added for an indicator widget. If the secondary measure gives a result greater than 1, the widget will show NA.

 

widget.on('render', function (se, ev) {
if(se.queryResult.secondary.data > 1)
{
   se.queryResult.value.text = "N/A";
}

});

 

 

 I want to achieve the same thing but for a column chart. I already have 3 values for the column chart and I added the 4th value which will determine NA scenario. The 4th value should not appear as a bar (it should be hidden), we are only using it in the script. However, I am not able to figure out the script for the same. 

 

  • Enable 4th panel and try this script

    widget.on('processresult', function(se, ev){
    
    	if(ev.result.series[0].data[3].y > 1)
    	{
    		ev.result.series = []
    		ev.rawResult.values = []
    	}
    	
    	ev.result.xAxis.categories.length = 3
    	ev.result.series.length = 3
    	ev.result.series[0].data.length = 3
    	
    })
    

    -Hari

6 Replies

Replies have been turned off for this discussion
  • harikm007's avatar
    harikm007
    Data Warehouse

    Hi Lisha ,

    Are you trying to display 'No Result' when the condition met? If yes, add widget filter using disabled value panel.

    For example: if you need to display 'No Result' when value of disabled panel is 1, then  - Enable the panel, add filter for the value panel and disable the the value panel

    Please reply if you are looking for something different

    -Hari

     

    • Lisha's avatar
      Lisha
      Cloud Apps

      Hi Hari,

      I need to display N/A or 'No Result' when value of disabled panel is >1. 

      Also, I don't have the filter option in my column chart since I don't have anything in my categories field (you can check the snapshot I have shared). 

      Thanks for your help

       

      • harikm007's avatar
        harikm007
        Data Warehouse

        I think it can be done in ways:

        • Add 'case statement' in Value 1, 2, 3 panels with condition 'NA measure <= 1'. For example:
          case when <Formula of NA Measure> <= 1 
          then <Formula of Value 1>
          else null
          end​

           

        •  Enable the 4th panel in your screenshot and add below script.
          widget.on('processresult', function(se, ev){
          
          	if(ev.result.series[0].data[3].y > 1)
          	{
          		ev.result.series[0].data[0].y = null
          		ev.result.series[0].data[1].y = null
          		ev.result.series[0].data[2].y = null
          		ev.result.series[0].data[3].y = null
          	}
          	
          	ev.result.xAxis.categories.length = 3
          	ev.result.series.length = 3
          	ev.result.series[0].data.length = 3
          })
          ​

        -Hari