我怎样才能改变转换" 120 Lakhs"到了1亿卢比20拉赫斯"在Highcharts

时间:2016-10-05 11:09:09

标签: javascript angularjs eclipse highcharts

我将此代码用于高图:

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

当我运行这个时,它显示了十万分之一的结果:20lakhs,40lakhs,80lakhs,120lakhs .... 但是我想要这个,(在99lakh之后)就像:120lakhs = 1crore 20lakhs。 我正在使用eclipse。

3 个答案:

答案 0 :(得分:0)

您可以覆盖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

答案 1 :(得分:-1)

这适用于jsFiddle。您还可以添加更多单位,例如数千或数百个。

var inputAmount = 12000000;
var oneCrore = 10000000;
var oneLakh = 100000;
var croreAmount = 0;
var lakhAmount = 0;

while(inputAmount >= oneCrore)
{
    croreAmount ++;
  inputAmount -= oneCrore;
}
while(inputAmount >= oneLakh)
{
    lakhAmount++;
  inputAmount -= oneLakh;
}

alert(croreAmount + "crore " + lakhAmount + "lakhs");

答案 2 :(得分:-2)

我刚刚开源paisa.js,您应该可以将其用作自定义标签格式化程序。

代码的相关部分如下所示:

const regulars = [
  {
    1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine'
  },
  {
    2: 'twenty', 3: 'thirty', 4: 'forty', 5: 'fifty', 6: 'sixty', 7: 'seventy', 8: 'eighty', 9: 'ninety'
  }
]

const exceptions = {
  10: 'ten',
  11: 'eleven',
  12: 'twelve',
  13: 'thirteen',
  14: 'fourteen',
  15: 'fifteen',
  16: 'sixteen',
  17: 'seventeen',
  18: 'eighteen',
  19: 'nineteen'
}

const partInWords = (part) => {
  if (parseInt(part) === 0) return
  const digits = part.split('')
  const words = []
  if (digits.length === 3) {
    words.push([regulars[0][digits.shift()], 'hundred'].join(' '))
  }
  if (exceptions[digits.join('')]) {
    words.push(exceptions[digits.join('')])
  } else {
    words.push(digits.reverse().reduce((memo, el, i) => {
      memo.unshift(regulars[i][el])
      return memo
    }, []).filter(w => w).join(' '))
  }
  return words.filter(w => w.trim().length).join(' and ')
}