Javascript 在饼图切片内放置标签(Highchart)
使用海图。我使用距离将标签定位在切片中,它在移动设备上居中,但在平板电脑或台式机上则不然。尺寸越大,标签就越靠近边缘。如何根据视口尺寸定位标签Javascript 在饼图切片内放置标签(Highchart),javascript,jquery,highcharts,pie-chart,Javascript,Jquery,Highcharts,Pie Chart,使用海图。我使用距离将标签定位在切片中,它在移动设备上居中,但在平板电脑或台式机上则不然。尺寸越大,标签就越靠近边缘。如何根据视口尺寸定位标签 plotOptions: { pie: { allowPointSelect: true, cursor: "pointer", dataLabels: { enabled: true, format: "<strong>{point.na
plotOptions: {
pie: {
allowPointSelect: true,
cursor: "pointer",
dataLabels: {
enabled: true,
format: "<strong>{point.name}</strong><br>{point.percentage:.0f}%",
distance: -60,
color: "white"
}
},
series: [ {
type: "pie",
data: [
{
name: "Not too much text here",
color: "#5cb85c",
y: 35
},
{
name: "Not too much text here",
color: "#5bc0de",
y: 30
},
{
name: "Less text here",
color: "#78629b",
y: 15
},
{
name: "Less text here",
color: "#f0ad4e",
y: 10
},
{
name: "Less text here",
color: "#d9534f",
y: 10
}
]
} ]
plotOptions:{
馅饼:{
allowPointSelect:true,
光标:“指针”,
数据标签:{
启用:对,
格式:“{point.name}
{point.percentage:.0f}%”,
距离:-60,
颜色:“白色”
}
},
系列:[{
键入:“馅饼”,
数据:[
{
名称:“此处文字不多”,
颜色:“5cb85c”,
y:35
},
{
名称:“此处文字不多”,
颜色:“5bc0de”,
y:30
},
{
名称:“此处文本较少”,
颜色:“78629b”,
y:15
},
{
名称:“此处文本较少”,
颜色:“f0ad4e”,
y:10
},
{
名称:“此处文本较少”,
颜色:“d9534f”,
y:10
}
]
} ]
编辑:您可以使用事先准备好的距离选项的变量。例如:
var windowSize = $(window).width();
var distance = -60;
if(windowSize > 700)
distance -= 30;
// else if...
在绘图选项.pie.dataLabels中:
distance: distance
你有完整的JSFIDLE吗?@Ondkloss我认为这是一个很好的解决方案。我希望我使用的Highcharts不正确,并且有一个内置选项?我同意。这远远不是最佳的。据我所知,没有任何选项可以直接实现这一点。而且,由于它是一个Ploth选项,所以渲染后不容易更改呃。希望有人能找到更可靠的解决方案,但至少这是一个可能的解决方案。你当然也可以使用你的容器宽度,如果这是距离值的一个更相关的指标。谢谢!我现在要使用这个解决方案,但请将它打开几天,看看是否有新的解决方案。