Joh*_*ine 4 javascript 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);
Run Code Online (Sandbox Code Playgroud)
更新:这里是 jsfiddle 链接:https ://jsfiddle.net/johnvaldetine/wmxtLoyu/3/
我检查了你的小提琴。似乎图表库提供了一个函数格式化程序。所以你可以像这样使用它:
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;
}
...
Run Code Online (Sandbox Code Playgroud)
有关工作示例,请参阅此小提琴:https : //jsfiddle.net/Lfrcbe9p/
| 归档时间: |
|
| 查看次数: |
5490 次 |
| 最近记录: |