【问题标题】:Highcharts: Pie Charts Labels PositionHighcharts:饼图标签位置
【发布时间】:2016-04-28 19:20:11
【问题描述】:

看下面的例子:

http://jsfiddle.net/klodoma/2xgkzyh4/

是否有任何设置可以更正确地放置标签而无需单独调整它们?

火狐应该更上一层楼,其他的应该更上一层楼……

代码:

$(function () {
    $('#container').highcharts({
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        plotOptions: {
            pie: {
                dataLabels: {
                    connectorWidth: 12,
                    style : {
                    fontSize: 25
                    }
                }
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox', 45.0],
                ['IE', 26.8],
                ['Safari', 8.5],
                ['Opera', 6.2],
                ['Others', 0.7]
            ]
        }]
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 300px"></div>

【问题讨论】:

  • 这是 Highcharts 的默认行为。您可以wrap position 方法或禁用 dataLabels 并使用renderer 添加自定义形状。

标签: highcharts pie-chart


【解决方案1】:

我一直发现饼图(以及极坐标图和蜘蛛图)的标签定位难以管理。根据您的数据和您想要的格式,它们可能会非常挑剔和不守规矩地按照您的喜好放置。

我建议完全删除标签并使用图例。我已经用这个概念更新了你的代码 sn-p。

如果这对您有帮助,请告诉我!

$(function () {
    $('#container').highcharts({
        title: {
            text: 'Browser market shares at a specific website, 2014'
        },
        legend: {
            enabled: true,
            borderWidth: 1,
            borderColor: 'gray',
            align: 'center',
            verticalAlign: 'top',
            layout: 'horizontal',
            x: 0, y: 50
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: { enabled: false },
                showInLegend: true
            }
        },
        series: [{
            type: 'pie',
            name: 'Browser share',
            data: [
                ['Firefox', 45.0],
                ['IE', 26.8],
                ['Safari', 8.5],
                ['Opera', 6.2],
                ['Others', 0.7]
            ]
        }]
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<div id="container" style="height: 300px"></div>

【讨论】:

  • 感谢您提出的解决方案。不确定它是否会被接受(这不是我的决定)。
  • 没问题。如果您需要任何进一步的意见或对其他替代方案的想法,请随时回复此主题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多