1

我有一个 highcharts 堆积条形图,其中有一些非常低的值。这会导致两个数据标签重叠,就像这个小提琴:http: //jsfiddle.net/cerjps88/

确保标签不能重叠的最佳方法是什么?

这是我的高图代码:

function getCostStackedColumnChart(series) {

    function costFilterPluck(costCollection, propertyName) {
        return _.chain(costCollection)
                .filter(function (f){
                    return Math.abs(f.metric_mean_patient_cost) > 0 && Math.abs(f.metric_mean_patient_cost_rx) > 0
                })
                .pluck(propertyName)
                .take(10)
                .value();
    }

    function shapeCostData(costCollection) {

        return [
            {
                name: 'RxCost Per Prescription',
                color: '#1aadce',
                data: costFilterPluck(series, 'metric_mean_patient_cost_rx')
            },
            {
                name: 'Retail Price Per Prescription (2014)',
                color: '#00FFFF',
                data: costFilterPluck(series, 'metric_drug_price_rx')
            }
        ];
    }

    return {
        options: {
            chart: {
                type: 'column'
            },
            tooltip: {
                formatter: function () {
                    var format = d3.format(",.2f");
                    var chart = this.point.series.chart;
                    var index = chart.xAxis[0].categories.indexOf(this.x);
                    var series1 = this.point.series;
                    return '<b>' + this.x + '</b><br/>' +
                            series1.name + ': $' + format(this.y);
                }
            },
            showInLegend: true,
            plotOptions: {
                column: {
                    grouping: true,
                    stacking: 'normal',
                    dataLabels: {
                        enabled: true,
                        allowOverlap: false,
                        format: '${y:,.2f}',
                        color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'black',
                        style: {
                            fontWeight: 'bold',
                            textShadow: '0 0 3px white'
                        },
                    }
                }
            }
        },
        xAxis: {
            stackLabels: {
                enabled: true,
                style: {
                    fontWeight: 'bold',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
                }
            },
            categories: costFilterPluck(series, 'aedrug_label'),
            title: {text: 'Drug'}
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Total Cost Per Prescription'
            }
        },
        tooltip: {
            shared: true
        },
        title: {
            text: drugGroupName + ' RxCost'
        },
        series: shapeCostData(series)
    };
}
4

1 回答 1

1

最新版本的 highcharts 会自动隐藏重叠的标签。升级新版本后,问题得到解决。

于 2015-03-13T04:00:51.373 回答