Jump to content
  • 0

Percentage in Y-Axis Values


eunha

Question

I'm trying to add  a percentage symbol in the Y-axis values of my Column Chart DataPage using the Formatting feature. They are displaying as percentage, however, all the values are being changed. I just want to add a percentage symbol and retain the values as is. Can someone help with this?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

This is possible using the formatter function of Highcharts. You may paste this on your DataPage Footer.

<script type = "text/javascript" >
var timer = setInterval(function() {
//Find if chart exists using rect element every x milliseconds
if (document.getElementsByTagName('rect') != null) {
//Update Chart
UpdateChart();
}
}, 500);
function UpdateChart() {
try {
Highcharts.charts[0].update({
yAxis: {
  labels: {
    formatter: function() {
       return this.value+"%";
    }
}
}
});
//Stop checking
clearInterval(timer);
} catch (err) {
//log errors
}
};
</script>

This will be the result:

image.png.c199aff07f7b43776276c8cdadbbd8c5.png

Link to comment
Share on other sites

  • 0
On 4/28/2022 at 6:14 PM, GoodBoy said:

This is possible using the formatter function of Highcharts. You may paste this on your DataPage Footer.

<script type = "text/javascript" >
var timer = setInterval(function() {
//Find if chart exists using rect element every x milliseconds
if (document.getElementsByTagName('rect') != null) {
//Update Chart
UpdateChart();
}
}, 500);
function UpdateChart() {
try {
Highcharts.charts[0].update({
yAxis: {
  labels: {
    formatter: function() {
       return this.value+"%";
    }
}
}
});
//Stop checking
clearInterval(timer);
} catch (err) {
//log errors
}
};
</script>

This will be the result:

image.png.c199aff07f7b43776276c8cdadbbd8c5.png

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
Answer this question...

×   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...