Knowledge Base Article

Define Widget Navigator Scroll Position

In some cases, it may be desirable to define the default location of a widget's navigation scroll bar. Users will still have the ability to expand and move the navigation scroller, but anytime the dashboard is reloaded, the scroller will default to the pre-defined position. 
The following widget script will default the navigation scroller to the maximum position. 
Configure the script via the displayBars variable. This is the number of bars that will be displayed. 
//======================= Configuration =======================
//Number of bars you would like to display, starting from the last bar
var displayBars = 10;
//================================================================

widget.on('processresult',function(widget,args){

     //define the maximum bar count to be the series length, minus 1 because the below is zero indexed. 
     var maxBarCount = (args.result.series[0].data.length - 1);

     args.widget.options.previousScrollerLocation.min = maxBarCount - displayBars + 1;
     args.widget.options.previousScrollerLocation.max = maxBarCount;
});
NAVIGATOR TO MINIMUM POSITION
The following widget script will default the navigation scroller to the maximum position. 
Configure the script via the displayBars variable. This is the number of bars that will be displayed. 
//======================= Configuration =======================
//Number of bars you would like to display, starting from the last bar
var displayBars = 10;
//================================================================

widget.on('processresult',function(widget,args){

     args.widget.options.previousScrollerLocation.min = 0;
     args.widget.options.previousScrollerLocation.max = displayBars - 1;
});
Updated 03-02-2023

1 Comment

  • intapiuser - The above is really useful, I don't suppose you or someone else may know how to adapt this to also include forecasts?  The script also seems to work for a line chart with dates across the x-axis, in that this will show me the last 14 days:

    //======================= Configuration =======================
    //Number of bars you would like to display, starting from the last bar
    var displayBars = 14;
    //================================================================
    
    widget.on('processresult',function(widget,args){
    
         //define the maximum bar count to be the series length, minus 1 because the below is zero indexed. 
         var maxBarCount = (args.result.series[0].data.length - 1);
    
         args.widget.options.previousScrollerLocation.min = maxBarCount - displayBars + 1;
         args.widget.options.previousScrollerLocation.max = maxBarCount;
    });

    However, it doesn't show me the forecast period, just the actual data points:

    Ideally, I am looking for something that shows the last 14 days, and also the forecast period, like this:

    Thanks,
    James