Javascript 在工具提示highchart Angular 2上显示百分比
您好,我有以下highchart配置,用于带有百分比值的普通柱状图Javascript 在工具提示highchart Angular 2上显示百分比,javascript,angular,highcharts,Javascript,Angular,Highcharts,您好,我有以下highchart配置,用于带有百分比值的普通柱状图 private _attendanceInputData: any = { chart: { type: 'column' }, title : { text : 'Daily Attendance Overview' }, xAxis: { categories: this._weekValues }, yAxis:
private _attendanceInputData: any = {
chart: { type: 'column' },
title : { text : 'Daily Attendance Overview' },
xAxis: {
categories: this._weekValues
},
yAxis: {
allowDecimals: false,
title: { text: ''},
min: 0,
max: 100,
labels: {
formatter:function() {
console.log(this.value); //0, 25, 50 , 75 , 100
var pcnt = (this.value / 100) * 100;
return pcnt + '%';
}
}
},
credits: {
enabled: false
},
series: [
{
name: 'Students',
data: this._studentAttendance,
color: '#3366cc'
},{
name: 'Staff',
data: this._staffAttendance,
color: '#accbfc',
}
]
};
但工具提示现在显示值,但不在值后显示“%”。怎么做?对不起,我是海图的新手。提前感谢各位。您需要告诉Highcharts工具提示的格式。为此,highcharts对象中有
工具提示
部分。要在每个值后面呈现“%”,可以使用以下代码段:
[...]
credits: {
enabled: false
},
tooltip: {
valueSuffix: '%'
},
series: [{
[...]
请参阅以获取参考您可以使用工具提示格式化程序功能在图表工具提示上显示%。它是一个回调函数,用于从头设置工具提示文本的格式。返回false可禁用序列上特定点的工具提示 支持HTML的子集。除非useHTML为true,否则工具提示的HTML将被解析并转换为SVG,因此这不是一个完整的HTML呈现程序。支持以下标记:
<b> , <strong>, <i>, <em>, <br/>, <span>.
你能创作一首小提琴吗对不起,索拉布,不知道怎么创作。基本上,它只是一个普通的柱形图,y轴是百分比,当你将鼠标移到(工具提示)上时,它应该显示值(我得到值),并在值后附加一个百分比。太棒了!非常感谢马丁。我可以限制显示的号码吗?因为我的一个百分比值是67.932892363873%,我只想把它限制在67.93。不管怎样?是的,你可以:是的,刚刚找到。谢谢你,马丁!你摇滚:)
chart = new Chart({
chart: {
type: 'line'
},
title: {
text: 'Linechart'
},
credits: {
enabled: false
},
tooltip: {
formatter: function() {
return this.y + '%';
}
},
series: [{
name: 'Line 1',
data: [1, 2, 3]
}]
});