如何在 Highcharts 中用百万和十亿首字母格式化 yaxis 值?
How to format yaxis value with millions and billion initial letter in Highcharts?
如何格式化我的 y 轴值,使它们呈现如下所示?
000 万美元、5 亿美元、1B 美元、1.5B 美元、2B 美元等
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
},
只需一个快速的内联三元条件就可以了
return '$' + (this.value / 1000 < 1 ? this.value + 'M' : this.value / 1000 + 'B')
在上下文中:
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:
如何格式化我的 y 轴值,使它们呈现如下所示?
000 万美元、5 亿美元、1B 美元、1.5B 美元、2B 美元等
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
},
只需一个快速的内联三元条件就可以了
return '$' + (this.value / 1000 < 1 ? this.value + 'M' : this.value / 1000 + 'B')
在上下文中:
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: