2

我有一个像这样的高图: 小提琴演示图 它是在 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

任何意见,将不胜感激。

标记

4

1 回答 1

1

您可以在设置 url 之前测试该点是否在 click 事件中具有值。但是,任何空点仍然会有指针光标,我还没有找到解决方法。


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;
                }
            }
        }
    }
}

于 2012-05-18T09:14:51.113 回答