在 GWT 可视化中分组 API(或:google 图表中的千位分隔符使用 Java)
Grouping in GWT visualization API (or: Thousands delimiter in google charts using Java)
我想使用 class com.google.gwt.visualization.client.DataTable 创建数据表。
在底层 Java脚本 API 中,google.visualization.NumberFormat 提供此选项(来自 https://developers.google.com/chart/interactive/docs/reference#numberformatter)
groupingSymbol A character to be used to group digits to the left of the decimal into sets of three. Default is a comma (,).
Javaclass好像没有那个属性。如何为我的 Java 代码中的列设置分组符号或数字格式作为格式字符串?我试过了
private static native void formatDataTable(DataTable dataTable, int numericColumn)
/*-{
var formatter = new google.visualization.NumberFormat(
{groupingSymbol: '.'});
formatter.format(dataTable, numericColumn);
}-*/;
但我只得到了
...[ERROR] - Uncaught exception escaped...google is not defined
在eclipse的开发模式控制台中。
编辑:更正代码示例
使用 JSNI 时,您无法像使用常规 Javascript 那样访问全局变量。来自 documentation:
When accessing the browser’s window and document objects from JSNI,
you must reference them as $wnd and $doc, respectively. Your compiled
script runs in a nested frame, and $wnd and $doc are automatically
initialized to correctly refer to the host page’s window and document.
因此,要使您的代码正常工作,您需要使用:
var formatter = new $wnd.google.visualization.NumberFormat({groupingSymbol: '.'});
我想使用 class com.google.gwt.visualization.client.DataTable 创建数据表。
在底层 Java脚本 API 中,google.visualization.NumberFormat 提供此选项(来自 https://developers.google.com/chart/interactive/docs/reference#numberformatter)
groupingSymbol A character to be used to group digits to the left of the decimal into sets of three. Default is a comma (,).
Javaclass好像没有那个属性。如何为我的 Java 代码中的列设置分组符号或数字格式作为格式字符串?我试过了
private static native void formatDataTable(DataTable dataTable, int numericColumn)
/*-{
var formatter = new google.visualization.NumberFormat(
{groupingSymbol: '.'});
formatter.format(dataTable, numericColumn);
}-*/;
但我只得到了
...[ERROR] - Uncaught exception escaped...google is not defined
在eclipse的开发模式控制台中。
编辑:更正代码示例
使用 JSNI 时,您无法像使用常规 Javascript 那样访问全局变量。来自 documentation:
When accessing the browser’s window and document objects from JSNI, you must reference them as $wnd and $doc, respectively. Your compiled script runs in a nested frame, and $wnd and $doc are automatically initialized to correctly refer to the host page’s window and document.
因此,要使您的代码正常工作,您需要使用:
var formatter = new $wnd.google.visualization.NumberFormat({groupingSymbol: '.'});