You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改highcharter地图Tooltip:移除Series 1及国名后多余内容

解决highcharter地图Tooltip自定义需求

要移除Tooltip里的"Series 1"文本,同时只保留国家名称(去掉名称后的冒号和数字1),只需在代码中添加hc_tooltip()配置,自定义提示框的显示格式即可:

修改核心要点:

  • headerFormat = "":清空默认的系列名称显示区域,直接去掉"Series 1"
  • pointFormat = "{point.name}":仅渲染国家名称,替换掉默认的{point.name}: {point.y}格式

完整修改后代码:

library(highcharter)
library(maps)
library(dplyr) # 显式加载dplyr,避免rename函数报错

countrylabeldata <- iso3166
countrylabeldata <- rename(countrylabeldata, "iso-a3" = a3)

Swahili_countries <- c("BDI","COD", "KEN", "OMN", "RWA", "TZA", "UGA")
countrylabeldata$include <- ifelse(countrylabeldata$`iso-a3` %in% Swahili_countries, 1, 0)

hcmap(
  map = "custom/world-highres3", 
  data = countrylabeldata, 
  joinBy = "iso-a3",
  value = "include",
  showInLegend = FALSE,
  nullColor = "#DADADA",
  download_map_data = TRUE,
) %>%
  hc_mapNavigation(enabled = T) %>%
  hc_legend("none") %>%
  hc_title(text = "Countries with Highest Prevalence of Swahili Speakers") %>%
  hc_caption(text="Data from CIA World Factbook") %>%
  # 新增自定义Tooltip配置
  hc_tooltip(
    headerFormat = "",
    pointFormat = "{point.name}"
  )

注:该配置对所有国家生效,包括灰色的非目标国家,鼠标悬停时只会显示对应的国家名称,无多余内容。

内容的提问来源于stack exchange,提问作者user20934000

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 15:52:48