如何将 Highmaps 工具提示 {point.value} 显示为字符串

How to display Highmaps tooltip {point.value} as string

我正在使用 Highmaps 显示美国县地图。我已经设置了它的选项,以在任何具有关联数据的县上显示一个简单的单行工具提示。这是执行此操作的 Highmaps 选项部分:

tooltip: {
    headerFormat: '',
    pointFormat: '{point.name}: <b>{point.value}</b><br/>'
},

这会创建工具提示,例如:Autauga,AL:1

我想显示四个词之一,而不是这个数值:“Good”,“Great”,“ Best”或“Error”- 分别对应于 {point.value} 为 1、2、3 或其他任何值.因此,如果地图上有一个 point.value 为 2 的县,我希望它在工具提示中显示为 "Autauga, AL: Great"。

您可以像这样格式化 tooltip

Fiddle demo

tooltip: {
  headerFormat: '',
  //pointFormat: '{point.name}: <b>{point.value}</b><br/>'
  formatter: function() {
    str = "";
    if (this.point.value > 0 && this.point.value < 1) {
      str = "Error";
    }
    if (this.point.value > 1 && this.point.value < 2) {
      str = "Good";
    }
    if (this.point.value > 2 && this.point.value < 3) {
      str = "Great";
    }
    if (this.point.value > 3 && this.point.value < 4) {
      str = "Best";
    }
    if (this.point.value > 4) {
      str = "Error";
    }
    return this.point.name + ': ' +
       str;
  }
},