Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HighCharts legend.value and legend.percent items to 2 decimal points Math.Round()

unfortunately with how lengthy this thing is I don't have a fiddle for it, as I didn't build it, but basically all I am trying to do is assure that these values get set to two decimal points, regardless of the value of it. If it's 100, I want it to read 100.00 and that is seemingly the issue I am having. The code for this section, which replaces a template value is this;

if (isLegend) {
            if (legendFooterTemplate) {
                legendFooterData = legendFooterTemplate.replace("highcharts.value", addCommasToLargeNumber(Math.round(totalValues * 100) / 100));
                legendFooterData = legendFooterData.replace("highcharts.percent", Math.round(totalPercent));

                legendTable.append("<tr>" + legendFooterData + "</tr>");
            }
            //make the legend visible
            legendTable.css("visibility", "visible");
        }

you can see it adds commas to larger numbers and takes that formatted number and plugs it into the template where highcharts.value and highcharts.percent live. I just want to know how I can manipulate the math.round() functions to make it have two decimal points no matter what. Thank you for any and all help, Nick G

like image 779
Nick G Avatar asked Sep 15 '25 01:09

Nick G


1 Answers

For percentage use:

this.percentage.toFixed(2)

Example: http://jsfiddle.net/jugal/dTMWP/

For other:

Highcharts.numberFormat(this.y,0)

Example: http://jsfiddle.net/CAKQH/24227/

like image 87
Lorenzo Avatar answered Sep 17 '25 15:09

Lorenzo