Chad Vincent
Chad Vincent

Reputation: 75

GWT-Charts ColumnFunction not working?

I just want to make sure I'm not doing something wrong before I file a bug/start digging in GWT-Charts code...

Trying to style a LineChart:

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);

(I had to add RoleType.STYLE myself, custom-built 0.9.11-SNAPSHOT off Master)

But adding that column results in (using new JSONObject(columns)):

{
  "0":{"sourceColumn":0}, 
  "1":{"sourceColumn":1, "label":"Data"}, 
  "2":{"calc":{}, "type":"string", "role":"style"}
}

Note the empty set for "calc"?

I tried just doing a ColumnFunction for Data (returning a flat value) in case the "style" Role required more than just adding to the RoleType Enum, and that also doesn't seem to be getting passed through.

The JSNI in DataViewColumn.setCalc(ColumnFunction) seems to be right to me, so I'm not sure where the issue lies...

UPDATE:

Putting debugging statements in the ColumnFunction showed it to be running, but the output didn't seem to be getting used.

Turns out that DataViewColumn.setCalc was missing the return statement in its JSNI wrapper.

Upvotes: 0

Views: 66

Answers (1)

Chad Vincent
Chad Vincent

Reputation: 75

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) {
        [email protected]::calc(Lcom/googlecode/gwt/charts/client/DataTable;I) (dataTable, row);
    };
}-*/;

Was not returning the value calculated by the function, just calculating it.

Adding "return" to the line in the innermost block fixes the issue.

Upvotes: 1

Related Questions