Jump to content

Stacking Bar Chart: show the total value


Recommended Posts

To achieve this, you may add the following code to the DataPage Footer section. 

Please do not forget to disable the HTML editor on the Advanced tab before pasting.

<script> 
 
document.addEventListener('DataPageReady', chartUpdateHandler); 
 
function chartUpdateHandler(event) {  
 const cleaner = function (interv) { 
  clearInterval(interv); 
 } 
 
 const interv = setInterval(() => { 
  if(!Highcharts) return; 
 
  const chart = Highcharts.charts.find(chart => chart !== undefined); 
  chart.update({ 
             
 yAxis: { 
            stackLabels: { 
                enabled: true, 
                formatter: function() { 
                    return Highcharts.numberFormat(this.total, 1, ',', '.'); 
                } 
            } 

        }, 
  }); 
 
  cleaner(interv); 
 
 }, 200); 
} 
</script> 

Hope this helps.

 

P. S. Please note that this code should work correctly in case you have 1 Chart DataPage deployed on the web-page.

Link to comment
Share on other sites

Hello @Abdulhafeez,

I updated the code once again. Please test it. 

It looks like the issue can be related to the slow Internet. As I can see, sometimes the request for the new data for the chart works out later than the Chart is rendered. 
I am checking for the options to fix this and will update this thread as soon as I find a solution.

Thanks. 

Link to comment
Share on other sites

  • 6 months later...
On 6/30/2022 at 6:08 AM, CoopperBackpack said:

To achieve this, you may add the following code to the DataPage Footer section. 

Please do not forget to disable the HTML editor on the Advanced tab before pasting.

<script> 
 
document.addEventListener('DataPageReady', chartUpdateHandler); 
 
function chartUpdateHandler(event) {  
 const cleaner = function (interv) { 
  clearInterval(interv); 
 } 
 
 const interv = setInterval(() => { 
  if(!Highcharts) return; 
 
  const chart = Highcharts.charts.find(chart => chart !== undefined); 
  chart.update({ 
             
 yAxis: { 
            stackLabels: { 
                enabled: true, 
                formatter: function() { 
                    return Highcharts.numberFormat(this.total, 1, ',', '.'); 
                } 
            } 

        }, 
  }); 
 
  cleaner(interv); 
 
 }, 200); 
} 
</script> 

Hope this helps.

 

P. S. Please note that this code should work correctly in case you have 1 Chart DataPage deployed on the web-page.

Hi, sharing in here a script that I found that allows you to check if an element exists (followed by your code if that element in fact exists) instead of using a timer (setInterval):

 

function waitForElm(selector) {
    return new Promise(resolve => {
        if (document.querySelector(selector)) {
            return resolve(document.querySelector(selector));
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(selector)) {
                resolve(document.querySelector(selector));
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });
}

 

 

 

 

To use it:

waitForElm('.some-class').then((elm) => {
    console.log('Element is ready');
    console.log(elm.textContent);
});
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...