cancel
Showing results for 
Search instead for 
Did you mean: 
iburiak
Sisense Team Member
Sisense Team Member

To display a solid line on the chart without using the "Display missing values as zeros" function

Sometimes there is a need to display a solid line on the chart without using the "Display missing values as zeros" function. Here is a widget script that will read the average value between two neighboring points and draw a line. 

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

    const series = result.result.series;




    for (let j = 0; j < series.length; j++) {

        const data = series[j].data;




        for (let i = 0; i < data.length; i++) {

            if (data[i].y === null) {

                let leftIndex = i - 1;

                let rightIndex = i + 1;




                while (leftIndex >= 0 && data[leftIndex].y === null) {

                    leftIndex--;

                }




                while (rightIndex < data.length && data[rightIndex].y === null) {

                    rightIndex++;

                }




                const leftValue = leftIndex >= 0 ? data[leftIndex].y : null;

                const rightValue = rightIndex < data.length ? data[rightIndex].y : null;




                if (leftValue === null && rightValue === null) {

                    data[i].y = 0; // You can change this default value

                } else {

                    const average = ((leftValue || 0) + (rightValue || 0)) / 2;




                    data[i].y = average;

                }

            }

        }

    }

});

 

Before:

iburiak_0-1704407033796.png


After:

iburiak_1-1704407033936.png

Leave a comment if this helped or if you need further assistance! 

Disclaimer: This blog post contains one possible custom workaround solution for users with similar use cases. We cannot guarantee that the custom code solution described in this post will work in every scenario or with every Sisense software version. As such, we strongly advise users to test solutions in their environment before deploying them to ensure that the solutions proffered function as desired. To avoid doubt, the content of this blog post is provided to you "as-is" and without warranty of any kind, express, implied, or otherwise, including without limitation any warranty of security and or fitness for a particular purpose. The workaround solution described in this post incorporates custom coding, which is outside the Sisense product development environment and is, therefore, not covered by Sisense warranty and support services.

 
Rate this article:
Version history
Last update:
‎01-15-2024 07:34 AM
Updated by: