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



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

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

这会创建工具提示,例如:autauga,al: 1

我想显示四个单词之一:" good ","或" error " - 对应于{point.value}分别为1、2、3或其他任何东西。因此,如果地图上有一个县,值为2,则我希望在工具提示中以" Autauga,al: great "的形式出现。

您可以像这样的tooltip格式化

小提琴演示

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;
  }
},

相关内容

最新更新