Step 4: Add data sources

Pentaho CTools

Version
10.2.x
Audience
anonymous
Part Number
MK-95PDIA006-12
In this example, you will use scripted queries as the data source.
  1. In the Data Source perspective, from the Data Source list, click SCRIPTING Queries, and then click scriptable over scripting twice.
  2. In the Datasources panel, in the Name column, enter chartQuery for the first data source, and tableQuery for the second.

    Datasources panel
  3. Add the following script to the Query property for the chartQuery data source:
    import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;
    String[] columnNames = new String[]{
      "Country", "Population growth per City [%]"
    };
    Class[] columnTypes = new Class[]{
      String.class, Float.class
    };
    TypedTableModel model = new TypedTableModel(columnNames, columnTypes);
    model.addRow(new Object[]{
      new String("Tokyo"), new Float("60")
    });
    model.addRow(new Object[]{
      new String("Nice"), new Float("20")
    });
    model.addRow(new Object[]{
      new String("London"), new Float("-10")
    });
    model.addRow(new Object[]{
      new String("Munich"), new Float("30")
    });
    model.addRow(new Object[]{
      new String("Porto"), new Float("10")
    });
    model.addRow(new Object[]{
      new String("Brasilia"), new Float("10")
    });
    
    return model;
  4. Add the following script to the Query property for the tableQuery data source:
    import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;
    String[] columnNames = new String[]{
      "Country", "City", "Population growth per City"
    };
    Class[] columnTypes = new Class[]{
      String.class, String.class, Float.class
    };
    TypedTableModel model = new TypedTableModel(columnNames, columnTypes);
    model.addRow(new Object[]{
      new String("Japan"), new String("Tokyo"), new Float("60")
    });
    model.addRow(new Object[]{
      new String("France"), new String("Nice"), new Float("20")
    });
    model.addRow(new Object[]{
      new String("UK"), new String("London"), new Float("-10")
    });
    model.addRow(new Object[]{
      new String("Germany"), new String("Munich"), new Float("30")
    });
    model.addRow(new Object[]{
      new String("Portugal"), new String("Porto"), new Float("10")
    });
    model.addRow(new Object[]{
      new String("Brazil"), new String("Brasilia"), new Float("10")
    });
    
    return model;