Vaadin 图表工具提示动态格式化程序
Vaadin Charts Tooltip dynamic formatter
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);;
}
这是一个例子:
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 来应用您的动态计算和格式。
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);;
}
这是一个例子:
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 来应用您的动态计算和格式。