[英]How to format yaxis value with millions and billion initial letter in Highcharts?
How can I format my y-axis values so that they render like the followings?如何格式化我的 y 轴值,以便它们呈现如下?
$0M, $500M, $1B, $1.5B, $2B, etc 000 万美元、5 亿美元、1B 美元、1.5B 美元、2B 美元等
https://jsfiddle.net/samwhite/xdLacn6m/1/ https://jsfiddle.net/samwhite/xdLacn6m/1/
yAxis: {
min: 0,
title: { text: yaxisTitle },
labels: {
formatter: function () {
if(this.chart.series[0].name === "Target Enterprise Value" || this.chart.series[0].name === "IPO Proceeds") {
return '$' + Highcharts.numberFormat(this.value, '', ', ') + 'M'
} else {
return this.value + '%'
}
},
style: { color: '#2B2B2B' }
},
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: '#2B2B2B',
lineWidth: 1
},
Just a quick inline ternary conditional did the trick只需一个快速的内联三元条件就可以了
return '$' + (this.value / 1000 < 1 ? this.value + 'M' : this.value / 1000 + 'B')
in context:在上下文中:
if (this.chart.series[0].name === "Target Enterprise Value" || this.chart.series[0].name === "IPO Proceeds") {
return '$' + (this.value / 1000 < 1 ? this.value + 'M' : this.value / 1000 + 'B')
} else {
return this.value + '%'
}
@jsfiddle: @jsfiddle:
https://jsfiddle.net/kinglish/0bzqs3yx/7/ https://jsfiddle.net/kinglish/0bzqs3yx/7/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.