高图表删除小数位



我正在使用高图表饼图并在中心通过以下方式显示数据。

function(chart1) { // on complete
var xpos = '50%';
var ypos = '50%';
var circleradius = 40;
// Render the circle
chart1.renderer.circle(xpos, ypos, circleradius).attr({
fill: '#fff',
}).add();
// Render the text 
chart1.renderer.text(chart1.series[0].data[0].percentage + '%', 62, 80).css({
width: circleradius * 2,
color: '#4572A7',
fontSize: '16px',
textAlign: 'center'
}).attr({
// why doesn't zIndex get the text in front of the chart?
zIndex: 999
}).add();
});

但是我想防止显示任何小数位,目前为 33.33333%。我想将其显示为 33%

这可能吗,我知道有一个设置allowDecimals但这不起作用。

您从点获得原始百分比值,该值未四舍五入。使用 JSMath.round函数:

chart1.renderer.text(Math.round(chart1.series[0].data[0].percentage) + '%', 62, 80)
.css({
width: circleradius * 2,
color: '#4572A7',
fontSize: '16px',
textAlign: 'center'
})
.attr({
zIndex: 999
})
.add();

现场演示:https://jsfiddle.net/BlackLabel/0z4hLbaw/

最新更新