Highmaps-需要使数据标签可单击

发布于 2025-01-27 15:26:15 字数 940 浏览 2 评论 0原文

我正在使用Highmaps中的美国小型地图,我想要每个状态,并且在单击时,它的数据标签可以打开一个新的URL。我有国家在工作,但标签行不通。

这就是我尝试的:

plotOptions: {
                series: {
                    allowPointSelect: true,
                    point: {
                        events: {
                            click: function(e) {
                                const url = e.target.point.value;
                                window.open(url);
                            }
                        }
                    },
          datalabels: {
                        events: {
                            click: function(e) {
                                const url = e.target.point.value;
                                window.open(url);
                            }
                        }
                    }
                }
            },

请参阅用于代码。

I'm using the small U.S. map in HighMaps and I want each state and it's datalabel to open up a new URL when clicked. I have the state working, but the label does not work.

this is what I tried:

plotOptions: {
                series: {
                    allowPointSelect: true,
                    point: {
                        events: {
                            click: function(e) {
                                const url = e.target.point.value;
                                window.open(url);
                            }
                        }
                    },
          datalabels: {
                        events: {
                            click: function(e) {
                                const url = e.target.point.value;
                                window.open(url);
                            }
                        }
                    }
                }
            },

Please see https://jsfiddle.net/sfjeld/zcsxobfa/12/ for the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦初启 2025-02-03 15:26:15

使用this.value而不是e.target.point.point.value

plotOptions: {
  series: {
    point: {
      events: {
        click: function() {
          const url = this.value;
          window.open(url);
        }
      }
    }
  }
}

demo:
https://jsfiddle.net/blacklabel/6gpl57nf/

Use the this.value instead of e.target.point.value:

plotOptions: {
  series: {
    point: {
      events: {
        click: function() {
          const url = this.value;
          window.open(url);
        }
      }
    }
  }
}

Demo:
https://jsfiddle.net/BlackLabel/6gpL57nf/

£烟消云散 2025-02-03 15:26:15

在您的示例中,您可以使用:

e.point.properties.hasc

从点击点获取值。

代码:

plotOptions: {
  series: {
    allowPointSelect: true,
    point: {
      events: {
        click: function(e) {
          const url = "https://www.google.com/search?q=" + e.point.properties.hasc;
          window.open(url);
        }
      }
    },
  }
},

您可以使用以下路径检查其他值:

console.log(e.point.properties);

完整代码在

In your example, you could use:

e.point.properties.hasc

For get the value from the clicked point.

Code:

plotOptions: {
  series: {
    allowPointSelect: true,
    point: {
      events: {
        click: function(e) {
          const url = "https://www.google.com/search?q=" + e.point.properties.hasc;
          window.open(url);
        }
      }
    },
  }
},

You can check other values using this path:

console.log(e.point.properties);

The full code is in this forked jsfiddle

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文