1

Vaadin Charts是否提供了一种即时格式化工具提示的方法。我想将一些逻辑绑定到工具提示上的值表示。代替 SOME_STRING,我需要reverseNormalization函数来更改值。

Map coefficients = new HashMap();
Chart chart = new Chart(ChartType.LINE);
Configuration conf = chart.getConfiguration();
Tooltip tooltip = conf.getTooltip();

tooltip.setFormatter(
  "function() { " +
    "return SOME_STRING }"
);

func reverseNormalization(String name, Double normalizedValue) {
    return normalizedValue * coefficients.get(name);;
}
4

1 回答 1

0

这是一个例子:

conf.getTooltip().setPointFormatter(
            "function() { " +
              "var category = this.x; " +
              "var multiplier = 10; " +
              "switch (category) " + 
              "{ " + 
              "   case 0: " + 
              "       multiplier = 10; " + 
              "       break; " + 
              "   case 1: " + 
              "       multiplier = 20; " + 
              "       break; " + 
              "   case 2: " + 
              "       multiplier = 30; " + 
              "       break; " + 

              "   default:  " + 
              "       multiplier = 50; " + 
              "}" +
              "var tipTxt = this.series.name + ': <b>' + this.y*multiplier + '</b><br>'; " +
              "return tipTxt; " +
              "}"  
            );

this.x将为您提供工具提示所呈现点的类别值(从零开始)。您可以使用 this.x、this.y 和 this.series.name 来应用您的动态计算和格式。

于 2018-06-06T02:08:13.100 回答