dataLabels for bar chart in Highcharts not displaying for null values in 3.0.8

自作多情 提交于 2019-12-25 06:37:39

问题


I've been using the following code to set dataLabels for bar charts in Highcharts...

plotOptions: {
    bar: {
        dataLabels: {
            enabled: true,
            formatter: function() {
                if (this.y==null) {
                    return '<i>(Suppressed)</i>';
                } else {
                    return '';
                }
            }
        }
    }
}

Basically, I want to be able to show the user when a value has been hidden for privacy reasons.

In previous versions of Highcharts, the label would show up for the null values as I desired. In version 3.0.8, I do not get any dataLabels for the null vales.

Is there a workaround or fix for this?


回答1:


Possibly bug, reported here https://github.com/highslide-software/highcharts.com/issues/2899

Workaround: use renderer http://api.highcharts.com/highcharts#Renderer.text




回答2:


As Sebastian points out, this is in fact a bug. However, there is an easy fix... In highcharts.src.js, simply change the call to the pick function for getting plotX and plotY in Series.prototype.alignDataLabel (lines 16132 and 16133) to:

plotX = pick(point.plotX, 0),
plotY = pick(point.plotY, 0),

rather than

plotX = pick(point.plotX, -999),
plotY = pick(point.plotY, -999),

Hope this ends up being helpful to somebody...



来源:https://stackoverflow.com/questions/22963501/datalabels-for-bar-chart-in-highcharts-not-displaying-for-null-values-in-3-0-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!