Warm tip: This article is reproduced from serverfault.com, please click

How to add distance/spacing between datalabels

发布于 2020-12-01 10:14:33

If i have large amount of data then data labels are overlapping. how to add spacing between data labels in this case .

[
https://jsfiddle.net/3ekhdqov/1/][1]
Questioner
Nita Patil
Viewed
0
ppotaczek 2020-12-01 21:17:14

There is no built-in logic for anit-collision data labels, but you can implement some, according to your needs. You can for example edit translateY attribute based on point's y value.

    chart: {
        zoomType: 'xy',
        events: {
            render: function() {
                var series = this.series;

                series[0].points.forEach(function(point, index) {
                    if (Math.abs(series[1].points[index].y - point.y) < 20) {
                        console.log(point.dataLabel)
                        point.dataLabel.attr({
                            translateY: point.dataLabel.y + 20
                        });
                    }
                });
            }
        }
    }

Live demo: https://jsfiddle.net/BlackLabel/bg0eyh2t/

API Refernece: https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr