[英]Highcharts - How can I get the name to display in the pie wedges?
I've got a pie chart up and running and the client I'm doing it for is requesting the name, which appears in the tooltip hover, to be in the pie wedge so that when it's printed out the names appear. 我有一个饼图并正在运行,我正在为此做的客户端要求将名称(出现在工具提示悬停中)放在饼形楔中,以便在打印出名称时出现。 I have tried using a png to overlay the chart with no luck, tried
distance: -60
and 我尝试使用png来覆盖图表,但是没有运气,尝试了
distance: -60
和
dataLabels: {inside: true,}
but none of them respond. 但他们都没有回应。 I asked here yesterday and someone mentioned that there's a line in the highcharts-more.src.js file which reads: "Align column data labels outside the columns. #1199."
我昨天在这里问,有人提到在highcharts-more.src.js文件中有一行,内容为:“在列外对齐列数据标签。#1199。” - is there anyway I can specify in the following JS to have the data labels, or names in this case, appear in the pie slices?
-无论如何,我可以在下面的JS中指定在饼图中显示数据标签或名称(在这种情况下为名称)吗?
JS: JS:
$(function () {
$('#container').highcharts({
chart: {
polar: true
},
title: {
text: 'Chart'
},
pane: {
startAngle: 0,
endAngle: 360
},
xAxis: {
tickInterval: 45,
min: 0,
max: 360,
labels: {
formatter: function () {
return;
}
}
},
yAxis: {
min: 0
},
plotOptions: {
series: {
pointStart: 0,
pointInterval: 45,
dataLabels: {
inside: true,
offset: -100,
formatter: function() {
if(this.y !== 0) {
return this.y.toFixed(1);
}
}
}
},
column: {
grouping: false,
pointPadding: 0,
groupPadding: 0
}
},
colors: [
'#FFD700',
'#458B00',
'#0099CC'],
series: [
{
type: 'column',
name: 'Behaviour',
shadow: true,
data: [
{y:0},
{y:0},
{y:0},
{y: 78, name: 'Be Deliberate', inside: true},
{y: 82, name: 'Consistent, reliable', inside: true},
{y:0},
{y:0},
{y:0}
],
dataLabels: {
enabled: true,
inside: true,
verticalAlign: 'top',
color: '#333333'
}
}, {
type: 'column',
name: 'Communication',
shadow: true,
data: [
{y:0},
{y:0},
{y:0},
{y:0},
{y:0},
{y: 80, name: 'Listen empathy'},
{y: 76, name: 'Communicate clear'},
{y: 88, name: 'Be honest transparent'}],
dataLabels: {
enabled: true,
inside: true,
color: '#333333'
}
}, {
type: 'column',
name: 'Action',
data: [
{y: 60, name: 'Act in clients best interests'},
{y: 70, name: 'Commit to do right thing'},
{y: 68, name: 'Deliver on promise'},
{y:0},
{y:0},
{y:0},
{y:0},
{y:0}
],
shadow: true,
groupPadding: 0,
pointPlacement: 'on',
dataLabels: {
enabled: true,
inside: true,
distance: -60,
color: '#333333'
}
}]
});
});
HTML: HTML:
<div id="container" style="min-width: 810px; max-width: 900px; height: 900px; margin: 0 auto"></div>
You had the correct location however your return
was never including the text you need. 您的位置正确,但是
return
永远不会包含您需要的文字。 Try: 尝试:
dataLabels: {
inside: true,
offset: -100,
formatter: function () {
if (this.y !== 0) {
return this.key + ' - ' + this.y.toFixed(1);
}
}
}
If you add return
modification you will see the same text in the tooltip appear in the dataLabel...And you now also see how that is rather ugly given the length of the text you are trying to render. 如果添加
return
修改,您将在工具提示中看到相同的文本,出现在dataLabel中...并且现在您还可以看到,鉴于要呈现的文本长度,这是多么难看。 There are overlaps all over the place. 到处都有重叠。 You can try and mitigate this by having the dataLabels moved further out from the bar (it is a bar, not a pie wedge as this is a polar chart and not a pie chart).
您可以通过使dataLabels从条形图上进一步移开(它是条形图,而不是饼形图,因为这是极坐标图而不是饼图)来尝试缓解这种情况。 You can try and mess with the formatting more but I think this is going to get uglier fast.
您可以尝试弄乱格式,但我认为这将变得更加难看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.