【问题标题】:Highcharts | How to avoid Pie charts inside labels overlap高图 |如何避免标签内的饼图重叠
【发布时间】:2021-03-04 14:14:01
【问题描述】:

我正在使用 highcharts PIE,并且想在切片上放置标签。但是,由于较小的值与相邻的较大值重叠。我已将“allowOverlap”属性设置为 false,这效果很好,直到图表有更新,例如悬停事件。

因此:

pie.series.dataLabel.allowOverlap=false

在更新之间不会持续存在。有没有办法处理这种情况?

参考资料:

  1. 内部标签 - https://api.highcharts.com/highcharts/series.column.dataLabels.inside.
  2. allowOverlap=false https://api.highcharts.com/highcharts/plotOptions.series.dataLabels.allowOverlap

【问题讨论】:

    标签: highcharts pie-chart overlap


    【解决方案1】:

    系列类型的 Pie 没有 dataLabels.inside,请改用 dataLabels.distance。 dataLabels.allowOverlap 没有记录 pie。这可能解释了意外的行为。

    您似乎遇到了错误,我建议您提交错误报告here

    禁用鼠标跟踪,可能是一个临时解决方案。

    Highcharts.chart('container', {
        chart: {
            plotBackgroundColor: null,
            plotBorderWidth: null,
            plotShadow: false,
            type: 'pie',
        },
        title: {
            text: 'Browser market shares in January, 2018'
        },
        tooltip: {
            pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
        },
        accessibility: {
            point: {
                valueSuffix: '%'
            }
        },
        plotOptions: {
            pie: {
                allowPointSelect: true,
                cursor: 'pointer',
                dataLabels: {
                    enabled: true,
                    distance: -30,
                    allowOverlap: false,
                    format: '<b>{point.name}</b>: {point.percentage:.1f} %',
                },
                enableMouseTracking: false,
            }
        },
        series: [{
            name: 'Brands',
            type: 'pie',
            colorByPoint: true,
            dataLabels:{ allowOverlap: false},
            data: [{
                name: 'Chrome',
                y: 61.41,
                sliced: true,
                selected: true,
            }, {
                name: 'Internet Explorer',
                y: 11.84
            }, {
                name: 'Firefox',
                y: 10.85
            }, {
                name: 'Edge',
                y: 4.67
            }, {
                name: 'Safari',
                y: 4.18
            }, {
                name: 'Sogou Explorer',
                y: 1.64
            }, {
                name: 'Opera',
                y: 1.6
            }, {
                name: 'QQ',
                y: 1.2
            }, {
                name: 'Other',
                y: 2.61
            }]
        }]
    });
    <script src="https://code.highcharts.com/highcharts.js"></script>
    <script src="https://code.highcharts.com/modules/exporting.js"></script>
    <script src="https://code.highcharts.com/modules/export-data.js"></script>
    <script src="https://code.highcharts.com/modules/accessibility.js"></script>
    
    <figure class="highcharts-figure">
        <div id="container"></div>
        <p class="highcharts-description">
            Pie charts are very popular for showing a compact overview of a
            composition or comparison. While they can be harder to read than
            column charts, they remain a popular choice for small datasets.
        </p>
    </figure>
    
    
    <script src="index.js"></script>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-26
      • 1970-01-01
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2017-07-11
      相关资源
      最近更新 更多