我想在工具提示中添加一个等级,它依赖于工具提示中的{point.y t.y}。这是我的转换功能:
function getGrade(score)
{
if(score >= 5-4/6)
return 'A';
if(score >= 5-4/6*2)
return 'B';
if(score >= 5-4/6*3)
return 'C';
if(score >= 5-4/6*4)
return 'D';
if(score >= 5-4/6*5)
return 'E';
if(score >= 5-4/6*6)
return 'F';
}
这是我的高图表配置:
$(function () {
$('#container').highcharts({
chart: {
polar: true,
type: 'line'
},
title: {
text: 'Budget vs spending',
x: -80
},
pane: {
size: '80%'
},
xAxis: {
categories: ['Sales', 'Marketing', 'Development', 'Customer Support',
'Information Technology', 'Administration'],
tickmarkPlacement: 'on',
lineWidth: 0
},
yAxis: {
gridLineInterpolation: 'polygon',
lineWidth: 0,
min: 0
},
tooltip: {
shared: true,
pointFormat: '<span style="color:{series.color}">{series.name}: <b>' + getGrade('{point.y:,.0f}') + '</b> ({point.y:,.0f})<br/>'
},
legend: {
align: 'right',
verticalAlign: 'top',
y: 70,
layout: 'vertical'
},
series: [{
name: 'Allocated Budget',
data: [1, 1, 2, 3, 4, 5],
pointPlacement: 'on'
}, {
name: 'Actual Spending',
data: [3, 4, 3, 2, 2, 2],
pointPlacement: 'on'
}]
});
});
这里是整个代码http://jsfiddle.net/A2uvs/
,有人有什么问题吗?
提前感谢!
发布于 2014-01-28 19:35:15
我觉得最好使用工具提示:格式化程序,因为您可以使用函数。看看这小提琴。它可能没有被完全格式化为你想要的,但我相信我已经让你大部分的方式在那里,其余的是样式为您决定,但功能在那里。
function getGrade(score){
if(score >= 5-4/6)
return 'A';
if(score >= 5-4/6*2)
return 'B';
if(score >= 5-4/6*3)
return 'C';
if(score >= 5-4/6*4)
return 'D';
if(score >= 5-4/6*5)
return 'E';
if(score >= 5-4/6*6)
return 'F';
}
$(function(){
$('#container').highcharts({
chart: {
polar: true,
type: 'line'
},
title: {
text: 'Budget vs spending',
x: -80
},
pane: {
size: '80%'
},
xAxis: {
categories: ['Sales', 'Marketing', 'Development', 'Customer Support', 'Information Technology', 'Administration'],
tickmarkPlacement: 'on',
lineWidth: 0
},
yAxis: {
gridLineInterpolation: 'polygon',
lineWidth: 0,
min: 0
},
tooltip: {
shared: true,
formatter: function() {
var s = '<b>'+ this.x +'</b>';
$.each(this.points, function(i, point) {
var tempcolor = point.series.color;
s += '<br/>'+ '<span style="color:'+ tempcolor+'">'+point.series.name +': '+ getGrade(point.y) +'('+point.y+')'+ '</span>';
});
return s;
}
},
legend: {
align: 'right',
verticalAlign: 'top',
y: 70,
layout: 'vertical'
},
series: [{
name: 'Allocated Budget',
data: [1, 1, 2, 3, 4, 5],
pointPlacement: 'on'
}, {
name: 'Actual Spending',
data: [3, 4, 3, 2, 2, 2],
pointPlacement: 'on'
}]
});
});
https://stackoverflow.com/questions/21414144
复制相似问题