这里有一个Highcharts饼图:http://jsfiddle.net/6PbbR/52/
$(function () {
var chart;
$(document).ready(function() {
// Radialize the colors
Highcharts.getOptions().colors = Highcharts.map(Highcharts.getOptions().colors, function(color) {
return {
radialGradient: { cx: 0.5, cy: 0.3, r: 0.7 },
stops: [
[0, color]
]
};
});
// Build the chart
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
shadow: true,
},
tooltip: {
enabled: false
},
title: {
text: ""
},
plotOptions: {
pie: {
allowPointSelect: true,
size:'68%',
cursor: 'pointer',
shadow: true,
dataLabels: {
enabled: true,
distance: -40,
style: {
width: '100px'
},
color: '#fff',
connectorColor: '#000000',
formatter: function() {
return '<b style="font-family:arial;font-size:10px;font-weight:bold">'+ this.point.name +'</b> ';
}
}
}
},
series: [{
type: 'pie',
name: 'Income Investments',
data: [
['FLOATING RATE FUNDS', 16.667],
{
name: 'Corporate Capital Trust',
y: 16.667,
sliced: true,
selected: true
},
['BONDS', 16.667],
['ANNUITIES', 16.667],
['REITs', 16.667],
['CDs', 16.667]
]
}],
colors: [
'#83a3c6',
'#98012e',
'#19699b',
'#ae9e8e',
'#5283b0',
'#958370'
],
});
});
});两个问题:
1)我对我在plotOptions{pie{格式化程序中插入内联样式的方式不满意。哪里有更好的地方使用API来完成这项工作,而不是使用暴力强制内联风格?
2)我想要更改红色楔形的字体系列(并可能调整其位置/边距)。做这件事的最好方法是什么?
编辑:理想情况下,我可以在不超出上述功能的情况下完成我的需求。是否可以使用API将样式仅附加到一个数据点?
发布于 2013-02-05 03:14:57
它是一个简单的html,所以您可以添加一个class或id,然后使用css设置样式。
js
formatter: function() {
return '<b id="myTooltipId">'+ this.point.name +'</b> ';
}css
#myTooltipId {
font-family: arial;
font-size: 10px;
font-weight:bold
}更新
在格式化程序中,您可以使用this获取切片属性。
所以你只需要检查切片是否是你想要的。
formatter: function() {
// key is the slice name
if (this.key == 'CDs') {
return '<b id="myTooltipId">'+ this.point.name +'</b> ';
} else {
return this.value;
}
}https://stackoverflow.com/questions/14691574
复制相似问题