echarts中如何将数字转换为货币?

How to convert numbers to currency in echarts?

我想在使用 echarts.js (v1) (https://ecomfe.github.io/) 构建的图表中将数字转换为土耳其里拉货币。你可以在下面看到我的图表和echarts js代码。

我的图表:

正如您在示例中所见,数字无法快速读取。所以,我想将“49146729.18 TL”转换为“49.146.729,18 TL”。 (在土耳其语中,我们使用“.”(点)分隔千位,使用“,”逗号分隔小数点。)

这是我的 echarts.js 代码:

// based on prepared DOM, initialize echarts instance
var myChart = echarts.init(document.getElementById('Cirolar'));

// specify chart configuration item and data
var option = {
    color: ['#ef6e6e'],
    tooltip: {
        formatter: '{c} TL',
    },
    grid: {
        width: '100%',
        left: '0%',
        top: '1%',
        bottom: '1%',
        containLabel: true
    },
    xAxis: {
        data: ["2017", "2016", "2015"]
    },
    yAxis: {
        axisLine: {
            show: false
        },
        axisLabel: {
            show: false
        },
        axisTick: {
            show: false
        },
        splitLine: {
            show: false
        }
    },
    series: [{
        name: 'Ciro',
        type: 'bar',
        // data: [5, 20, 36, 10, 10, 20]
        data: [{
                value: price2017.replace(/,/g, '.'),
                name: '2017'
            },
            {
                value: price2016.replace(/,/g, '.'),
                name: '2016'
            },
            {
                value: price2015.replace(/,/g, '.'),
                name: '2015'
            }

        ],
        label: {
            normal: {
                formatter: '{c} TL',
                show: true,
                position: 'inside'
            },
        }
    }]
};

// use configuration item and data specified to show chart
myChart.setOption(option);

更新: 这里是 jsfiddle link:https://jsfiddle.net/johnvaldetine/wmxtLoyu/3/

我检查了你的fiddle。似乎图表库提供了一个函数格式化程序。所以你可以这样使用它:

function format(data)
{
    data = parseFloat(data);
    return data.toLocaleString('tr-TR', {style: 'currency', currency: 'TRY'});
}

... //Inside the options
formatter: function (params) {
        var val = format(params.value);
    return val;
}
...

请参阅此 fiddle 以获取工作示例: https://jsfiddle.net/Lfrcbe9p/