This DataModelUtil class facilitates manipulation of data in data model or data collections.
This class contains static methods, which allows to manipulate matrix and array data model, i.e. for the matrix to soften() and normalize() matrix. Method logbase() allows to convert data logarithmic scale.
Method swapDataColumns() allows to swap specified data columns in the model. Very useful if you want to exchange horizontal and vertical bar model.
This class also contains two methods which allows to convert 2D arrays and collections to proper format for data model.
The data model accepts such format:
Object[][] data = new Object[][]{new String[]{"Lemon","Nuts"},new Double[]{3.6d, 5.6d}}; |
but using this converter we can make data from array like this:
Object[][] data = new Object[][]{new Object[]{"Lemon",3.6d},new Object[]{"Nuts", 5.6d}}; |
The same logic applies and for the collections.
The following example, shows how to use this class:
1 | ArrayList<Object[]> data = new ArrayList<Object[]>(); data.add(new Object[]{"January", new Double(15)}); data.add(new Object[]{"February", new Double(10)}); data.add(new Object[]{"March", new Double(10)}); DataModel dataModel = new ChartDataModel(new DataValueType[] { DataValueType.KEY, DataValueType.VALUE }, DataModelUtil.convert(data)); |