我有一张这样的图表: fiddle demo chart 它是在带有数据的 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;
}
}
}
}
}
关于php - 有一些酒吧不是 highcharts 上的 url 链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10646443/