在highchart格式化后,工具提示未隐藏

时间:2015-06-17 04:40:07

标签: javascript jquery css highcharts

我通过格式化隐藏数据标签的0值。它工作正常。但是在使用0值数据格式化工具提示后,当我将鼠标悬停在饼图中的0值部分时,它会显示白色框,如图所示。我将返回null作为0值的工具提示。

enter image description here

这是代码:

.directive('hcPie', function() {
var firstValue = 1;
return {
    restrict: 'C',
    replace: true,
    template: '<div id="container" style="margin: 0 auto; width:70%; height: 60%;"></div>',
    scope: {
        item: '='
    },
    link: function(scope, element, attrs, filter) {
        var chart = new Highcharts.Chart({
            chart: {
                renderTo: $(element).attr('id'),
                backgroundColor: '#F8F8F8',
                style: {
                    fontFamily: 'Verdana, Arial, sans-serif'
                }
            },
            title: {
                text: "",
            },
            plotOptions: {
                pie: {
                    animation: false,
                    allowPointSelect: false,
                    dataLabels: {
                        enabled: true,
                        style: {
                            fontSize: '13px',
                            fontFamily: 'Verdana, Arial, sans-serif',
                            fontWeight: 'normal'
                        } ,
                        formatter:function() {
                            if(this.y != 0) {
                                return this.point.name + ':' + this.point.sizeText;
                            } else {
                                return null;
                            }
                        }
                    },
                    showInLegend: false
                }
            },
            credits: {
                enabled: false
            },
            tooltip: {
                formatter:function() {
                    if(this.y != 0) {
                        return this.point.name + ':' + this.point.sizeText;
                    } else {
                        return null;
                    }
                }
            },
            series: [{
                type: 'pie',
                data: [
                    {
                        name: 'Personal Files',
                        y: scope.item.personalUsage,
                        sizeText: scope.item.personalUsageSizeText
                    },
                ]
            }]
        });
    }
}

});

2 个答案:

答案 0 :(得分:1)

想出来。返回null代替 tooltip: { formatter:function() { if(this.y != 0) { return this.point.name + ':' + this.point.sizeText; } else { return false; } } } 正在运作

{{1}}

答案 1 :(得分:1)

返回null没有任何意义,你应该在else条件中返回false。如果返回null将给出空的工具提示而false将不会创建工具提示。

  tooltip: {
            formatter:function() {
                if(this.y != 0) {
                    return this.point.name + ':' + this.point.sizeText;
                } else {
                    return false;
                }
            }
        },