javascript - 我如何在 Highcharts 中将 "120 Lakhs"更改为 "1 crore 20 Lakhs"

标签 javascript angularjs eclipse highcharts

我将此代码用于 Highcharts :

Highcharts.setOptions({
    lang : {
        numericSymbols : [ ' thousands', ' Lakhs', ' Crores' ]
    }
});

当我运行这个时,它显示的结果是十万,例如:200万、400万、800万、1200万...... 但我想要这个,(990万之后)千万像:1200万= 1千万200万。 我正在使用 Eclipse。

最佳答案

您可以覆盖defaultLabelFormatter

Highcharts.Axis.prototype.defaultLabelFormatter = function () {
    var axis = this.axis,
        value = this.value,
        categories = axis.categories,
        dateTimeLabelFormat = this.dateTimeLabelFormat,
        numericSymbols = Highcharts.getOptions().lang.numericSymbols,
        i = numericSymbols && numericSymbols.length,
        multi,
        ret,
        formatOption = axis.options.labels.format,

        // make sure the same symbol is added for all labels on a linear axis
        numericSymbolDetector = axis.isLog ? value : axis.tickInterval;

    if (formatOption) {
        ret = Highcharts.format(formatOption, this);

    } else if (categories) {
        ret = value;

    } else if (dateTimeLabelFormat) { // datetime axis
        ret = Highcharts.dateFormat(dateTimeLabelFormat, value);

    } else if (i && numericSymbolDetector >= 1000) {
        // Decide whether we should add a numeric symbol like k (thousands) or M (millions).
        // If we are to enable this in tooltip or other places as well, we can move this
        // logic to the numberFormatter and enable it by a parameter.
        while (i-- && ret === UNDEFINED) {
            multi = Math.pow(1000, i + 1);
            if (numericSymbolDetector >= multi / 10 && numericSymbols[i] !== null) {
                ret = Highcharts.numberFormat(value / multi, -1) + numericSymbols[i];
            }
        }
    }

    if (ret === UNDEFINED) {
        if (mathAbs(value) >= 10000) { // add thousands separators
            ret = numberFormat(value, 0);

        } else { // small numbers
            ret = numberFormat(value, -1, UNDEFINED, ''); // #2466
        }
    }

    return ret;
},
Highcharts.setOptions({
    lang : {
        numericSymbols : [ ' thousands', ' Lakhs', ' Crores' ]
    }
});

检查这个 DEMO

关于javascript - 我如何在 Highcharts 中将 "120 Lakhs"更改为 "1 crore 20 Lakhs",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39872361/

相关文章:

javascript - 用 replace() 替换 HTML 部分?

javascript - 在 Javascript 中来回更改 boolean 值

javascript - Angularjs Firebase 获取数据列表

javascript - Angularjs根据true false状态更改文本

Eclipse Scout 在离开页面时进行检查

javascript - 谷歌地图自动完成 InvalidValueError : not an instance of HTMLInputElement

javascript - 使用 Javascript/Bootstrap Checkbox 删除 Laravel 路由

javascript - ng-repeat 运行与整数参数一样多的次数在某些情况下不起作用

eclipse galileo 无法在 mac 上发布到 tomcat!

eclipse - 安装适用于 Eclipse Neon 的 AWS 工具包时出错