function formatIndianSuffix(num) {
var x = parseInt(num).toString();
var len = x.length;
var formattedNum = "";
if (len <= 3) {
formattedNum = '₹' + Math.floor(x);
} else if (len > 3 && len < 6) {
formattedNum = '₹' + (roundOff(x / 1000)).toString() + ' K'
} else if (len >= 6 && len < 8) {
formattedNum = '₹' + (roundOff(x / 100000)).toString() + ' L'
} else if (len >= 8) {
formattedNum = '₹' + (roundOff(x / 10000000)).toString() + ' Cr'
}
return formattedNum;
}
我正在使用此函数格式化数字,但如何在图表中使用它?
答案 0 :(得分:4)
完全披露,我是ZingChart团队的成员。
我们支持构建比例标签的功能。这是一个类似想法的工作示例。
var gFactor = 1.000;
var gFactorMultiplier = 1000;
var myConfig = {
type: "bar",
scaleY:{
"factor": gFactor,
"format":"formatMyLabels()",
label:{
text:"Size"
}
},
plotarea:{
margin: "dynamic"
},
series : [
{
values : [899,1024,1142,2267,3389,4425,5534,6667,7785]
}
]
};
window.formatMyLabels = function(v) {
var localFactor = gFactor * gFactorMultiplier;
switch(localFactor) {
case 1000:
if (v < 1000) {
return v;
} else if (v >= 1000 && v < 1000000) {
return v/1000 + 'K'
} else if (v >= 1000000) {
return v/1000000 + 'M'
}
break;
case 1024:
if (v < 1024) {
return v + 'bps';
} else if (v >= 1024) {
return v/1024 + 'kbps';
}
break;
}
}
zingchart.render({
id : 'myChart',
data : myConfig,
height: 400,
width: '100%'
});
<!DOCTYPE html>
<html>
<head>
<!--Assets will be injected here on compile. Use the assets button above-->
<script src= 'https://cdn.zingchart.com/zingchart.min.js'></script>
<script> ZC.MODULESDIR = 'https://cdn.zingchart.com/modules/';</script>
<!--Inject End-->
</head>
<body>
<div id='myChart'></div>
</body>
</html>
答案 1 :(得分:-1)
您可以将@nardecky中的window.formatMyLabels
示例与paisa.js结合使用,以获得所需内容。