php - 有一些酒吧不是 highcharts 上的 url 链接

标签 php javascript highcharts

我有一张这样的图表: 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/

相关文章:

php - 仅显示来自 PHP 和 MySQL 的最新三个结果

php - 识别可疑登录的可靠方法有哪些?

javascript - window.print 在 IE 和 Chrome 中打印不同的 URL?

javascript - 工具提示中的 Highcharts 表格样式不起作用

php - 在没有收到 "Node no longer exists"警告的情况下检查属性是否存在

php - 使用准备好的语句创建 MySQL 用户?

javascript - 是否可以通过使用 dc.js 选择表格元素来过滤数据?

javascript - 为什么 `keyof any` 在 typescript 中的类型为 `string | number | symbol`?

javascript - 如何将 Highcharts 图表渲染到用户选择的 DIV 中

php - 获取当前日期值到自己的时间