Rounding results in highcharts jquery script

后端 未结 6 1296
庸人自扰
庸人自扰 2021-02-07 04:20

I know this is a bit out there... but gonna ask anyways. I\'m using highcharts jquery script (http://www.highcharts.com/) to generate a pie chart. I am trying to round off the n

6条回答
  •  情深已故
    2021-02-07 04:39

    There's a numberFormatfunction available in the Highcharts API that you can use (see http://www.highcharts.com/ref/#highcharts-object).

    Quoted from API doc:

    numberFormat (Number number, [Number decimals], [String decimalPoint], [String thousandsSep]) : String

    Formats a JavaScript number with grouped thousands, a fixed amount of decimals and an optional decimal point. It is a port of PHP's function with the same name. See PHP number_format for a full explanation of the parameters.

    tooltip: {
        formatter: function() {
            return ''+ this.series.name +''+
                this.x +': '+ Highcharts.numberFormat(this.y, 0, ',') +' millions';
        }
    }, ...
    

    Parameters

    • number: Number The raw number to format.
    • decimals: Number The desired number of decimals.
    • decimalPoint: String The decimal point. Defaults to "." or to the string specified globally in options.lang.decimalPoint.
    • thousandsSep: String The thousands separator. Defaults to "," or to the string specified globally in options.lang.thousandsSep.

    Returns

    A string with with the input number formatted.

提交回复
热议问题