GWT-Charts ColumnFunction 不起作用?
GWT-Charts ColumnFunction not working?
我只是想在提交 bug/start 挖掘 GWT-Charts 代码之前确保我没有做错什么...
正在尝试设置折线图的样式:
DataViewColumn ret = DataViewColumn.create(new ColumnFunction() {
@Override
public Object calc(DataTable dataTable, int row) {
if (dataTable.isValueNull(i, dataColumn)
|| dataTable.getValueNumber(i, dataColumn) < value) {
return "color: red";
}
return "color: green";
}
}, ColumnType.STRING);
ret.setRole(RoleType.STYLE);
(我不得不自己添加 RoleType.STYLE,定制的 0.9.11-SNAPSHOT off Master)
但是添加该列会导致(使用新的 JSONObject(columns)):
{
"0":{"sourceColumn":0},
"1":{"sourceColumn":1, "label":"Data"},
"2":{"calc":{}, "type":"string", "role":"style"}
}
注意 "calc" 的空集?
我尝试只为数据做一个 ColumnFunction(returning 一个平面值)以防 "style" Role 需要的不仅仅是添加到 RoleType 枚举,而且这似乎也不是即将通过。
DataViewColumn.setCalc(ColumnFunction) 中的 JSNI 似乎对我来说是正确的,所以我不确定问题出在哪里...
更新:
在 ColumnFunction 中放置调试语句显示它是 运行,但输出似乎没有被使用。
原来 DataViewColumn.setCalc 在其 JSNI 包装器中缺少 return 语句。
DataViewColumn.setCalc:
/**
* Sets a function that will be called for each row in the column to calculate a value for that cell.
*
* @param columnFunction a function for calculating each row value
*/
public final native void setCalc(ColumnFunction columnFunction) /*-{
this.calc = function(dataTable, row) {
columnFunction.@com.googlecode.gwt.charts.client.ColumnFunction::calc(Lcom/googlecode/gwt/charts/client/DataTable;I) (dataTable, row);
};
}-*/;
没有返回函数计算的值,只是计算它。
将 "return" 添加到最里面的块中的行可以解决问题。
我只是想在提交 bug/start 挖掘 GWT-Charts 代码之前确保我没有做错什么...
正在尝试设置折线图的样式:
DataViewColumn ret = DataViewColumn.create(new ColumnFunction() {
@Override
public Object calc(DataTable dataTable, int row) {
if (dataTable.isValueNull(i, dataColumn)
|| dataTable.getValueNumber(i, dataColumn) < value) {
return "color: red";
}
return "color: green";
}
}, ColumnType.STRING);
ret.setRole(RoleType.STYLE);
(我不得不自己添加 RoleType.STYLE,定制的 0.9.11-SNAPSHOT off Master)
但是添加该列会导致(使用新的 JSONObject(columns)):
{
"0":{"sourceColumn":0},
"1":{"sourceColumn":1, "label":"Data"},
"2":{"calc":{}, "type":"string", "role":"style"}
}
注意 "calc" 的空集?
我尝试只为数据做一个 ColumnFunction(returning 一个平面值)以防 "style" Role 需要的不仅仅是添加到 RoleType 枚举,而且这似乎也不是即将通过。
DataViewColumn.setCalc(ColumnFunction) 中的 JSNI 似乎对我来说是正确的,所以我不确定问题出在哪里...
更新:
在 ColumnFunction 中放置调试语句显示它是 运行,但输出似乎没有被使用。
原来 DataViewColumn.setCalc 在其 JSNI 包装器中缺少 return 语句。
DataViewColumn.setCalc:
/**
* Sets a function that will be called for each row in the column to calculate a value for that cell.
*
* @param columnFunction a function for calculating each row value
*/
public final native void setCalc(ColumnFunction columnFunction) /*-{
this.calc = function(dataTable, row) {
columnFunction.@com.googlecode.gwt.charts.client.ColumnFunction::calc(Lcom/googlecode/gwt/charts/client/DataTable;I) (dataTable, row);
};
}-*/;
没有返回函数计算的值,只是计算它。
将 "return" 添加到最里面的块中的行可以解决问题。