gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:17:31 24 4
gpt4 key购买 nike

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

我的图表:

My Chart that was built with echart.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 链接: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/

关于javascript - echarts中如何将数字转换为货币?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53332419/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com