I want to convert numbers to Turkish Lira currency in my charts that was built with echarts.js (v1) ( https://ecomfe.github.io/ ). You can see my charts and echarts js codes below.
My chart:
As you can see the example, the numbers are not readable quickly. So, i want to convert "49146729.18 TL" to "49.146.729,18 TL". (In Turkish, we use "." (dot) for separating thousand, use "," comma for separating decimal.)
Here is my echarts.js code:
// 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);
Update: here is the jsfiddle link: https://jsfiddle.net/johnvaldetine/wmxtLoyu/3/
I checked your fiddle. Seems like the chart library offers a function formatter. So you could use it like this:
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;
}
...
See this fiddle for a working example: https://jsfiddle.net/Lfrcbe9p/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.