有一些条形图不是高图表上的 url 链接


Have some bars not a url link on highcharts

我有一个这样的高图表:小提琴演示图表它是在 PHP 的服务器上用数据生成的,但如果数据计数为零,我不希望它有一个 URL(因为没有什么可看的(。

如何告诉图表仅禁用这些柱上的链接?

if($value['category'] > 0){
        $chartActive .= $comma."{y:".$value['category'].", url: '/section/of/site/index.php'}";
    }else{
        $chartActive .= $comma."{y:0, url: javascript:void(0)}";
    }

然后,这将像这样添加到图表中:

plotOptions: {
            column: {
                stacking: 'normal',
                dataLabels: {
                    enabled: true,
                    color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || '#333'
                }
            },
            series: {
                cursor: 'pointer',
                point: {
                    events: {
                        click: function() {
                            location.href = this.options.url;
                        }
                    }
                }
            }
        },
        series: [{
            name: 'Active',
            data: [<?php echo $chartActive; ?>]
        },

如您所见,url 是在 plotOptions 的系列部分中定义的,因此它始终存在,如果我按照我现在的方式进行操作,链接可以工作但转到 mysite.com/undefined

任何建议将不胜感激。

马克

您可以在设置 url 之前测试该点是否在点击事件中具有值。但是,任何空点仍将具有指针光标,我还没有找到绕过它的方法。


series: {
    cursor: 'pointer',
    point: {
        events: {
            click: function() {
// if you've more than one series then you'll have to sum up the value for the stack
                if (this.y != 0) {  
                    location.href = this.options.url;
                }
            }
        }
    }
}