我想要一个饼图里面和外面饼datalabels。 我知道,有一个负距离它显示了馅饼内侧的标签。 但我想它内部和外部。 外面我想显示百分比和点的总和内。
Answer 1:
你有没有可能来设置双datalabels,但你可以使用的解决方法,这是不完美的,但也许会有所帮助。 所以,你可以设置useHTML,然后格式化器返回两个div,第一个适当的datalabel(外)和第二里面。 然后设置ID与计数器,它定义每个div的id作为唯一的,那么只需要设置相应的CSS什么。 位置的一个datalabel的例子可以在这里找到: http://jsfiddle.net/4RKF4/
$(function () {
var chart,
counter = 0;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'Browser market shares at a specific website, 2010'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
useHTML:true,
formatter: function() {
counter++;
return '<div class="datalabel"><b>'+ this.point.name +'</b>: '+ this.percentage +' %</div><div class="datalabelInside" id="datalabelInside'+counter+'"><b>'+ this.point.name +'</b>: '+ this.percentage +' %</div>';
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
});
});
});
CSS样式:
.datalabelInside {
position:absolute;
}
#datalabelInside1 {
color:#fff;
left:-150px;
}
Answer 2:
有一个简单的工作,以防万一吧
那是你覆盖2馅饼diferent datalabels
http://jsfiddle.net/4RKF4/29/
$(function () {
// Create the chart
$('#container').highcharts({
chart: {
type: 'pie',
backgroundColor: 'rgba(0,0,0,0)',
y:100
},
title: {
text: 'sfs '
},
yAxis: {
title: {
text: ' '
}
},
plotOptions: {
pie: {
// y:1,
shadow: false,
// center: ['50%', '50%'],
borderWidth: 0,
showInLegend: false,
size: '80%',
innerSize: '60%'
,
data: [
['allo', 18],
['asdad', 14],
['asdad', 11],
['asdasd', 10],
['adad', 8],
['asdada', 7],
['adada ada', 7],
['adad', 5],
['asdas',7],
['ada', 3]
]
}
},
tooltip: {
valueSuffix: '%'
},
series: [
{
type: 'pie',
name: 'Browser share',
dataLabels: {
color:'white',
distance: -20,
formatter: function () {
if(this.percentage!=0) return Math.round(this.percentage) + '%';
}
}
},
{
type: 'pie',
name: 'Browser share',
dataLabels: {
connectorColor: 'grey',
color:'black',
// y:-10,
softConnector: false,
connectorWidth:1,
verticalAlign:'top',
distance: 20,
formatter: function () {
if(this.percentage!=0) return this.point.name;
}
}
}
]
});
});
文章来源: Highcharts pie dataLabels inside and outside