在饼图切片内放置标签(Highchart) [英] Placing labels inside pie chart slices (Highchart)

查看:181
本文介绍了在饼图切片内放置标签(Highchart)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Highchart。我使用距离将标签放置在切片内部,并且它在移动设备上居中,但不在平板电脑或台式机上。随着尺寸变大,标签太靠近边缘。如何根据视口尺寸定位标签?

Using Highchart. I am positioning the labels inside the slices using distance and it centers well on mobile, but not on tablets or desktops. As the dimensions become larger, the labels get too close to the edges. How to position labels depending on viewport dimensions?

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/

推荐答案

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

You could use a variable for the distance-option which you've prepared beforehand. For example:

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

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

并且在 plotOptions .pie.dataLabels

distance: distance

这篇关于在饼图切片内放置标签(Highchart)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆