javascript - 将标签放置在饼图切片内(Highchart)

标签 javascript jquery highcharts pie-chart

使用 Highcharts 。我使用距离将标签放置在切片内,它在移动设备上很好地居中,但在平板电脑或台式机上则不然。随着尺寸变大,标签会变得太靠近边缘。如何根据视口(viewport)尺寸定位标签?

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
                }
            ]
        } ]

编辑:http://jsfiddle.net/TimNguyenBSM/rL1bwam6/1/

最佳答案

您可以使用事先准备好的distance选项的变量。例如:

var windowSize = $(window).width();
var distance = -60;

if(windowSize > 700)
    distance -= 30;
// else if...

在你的plotOptions.pie.dataLabels中:

distance: distance

关于javascript - 将标签放置在饼图切片内(Highchart),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25334551/

相关文章:

javascript - 使用 VB.net 获取 JSON 格式

JavaScript 有没有办法阻止 href ="#"刷新页面?尼龙莫代尔

javascript - 如何在 .keypress(); 中的两个函数之间切换?

asp.net-mvc-3 - 如何使用 dotnet highcharts dll 在 MVC3 中显示 HighCharts?

javascript - 构建要发送到 View 中的 HighCharts 的数据

javascript - [Element].onXXX 可以用来制造不平凡的黑客问题吗?

javascript - ASP.NET Ajax-OnFailure-获取错误文本

javascript - 如何在javascript中更改urlpath

javascript - 使用 javascript-jQuery 函数设置 css 属性

javascript - 无法在 Highcharts 中使用 [null,null] 和不规则间隔断开折线图