Search in sources :

Example 31 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class ChartContentGenerator method getContent.

@Override
public String getContent() throws Exception {
    // $NON-NLS-1$
    int chartType = (int) requestParameters.getLongParameter("ChartType", JFreeChartEngine.UNDEFINED_CHART_TYPE);
    // $NON-NLS-1$
    String chartDefinitionPath = requestParameters.getStringParameter("ChartDefinitionPath", null);
    ArrayList messages = new ArrayList();
    CategoryDatasetChartComponent barChart = new CategoryDatasetChartComponent(chartType, chartDefinitionPath, 600, 400, urlFactory, messages);
    String content = null;
    IPentahoConnection connection = // $NON-NLS-1$
    PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, "SampleData", userSession, this);
    try {
        // $NON-NLS-1$
        String query = "select department, actual, budget, variance from QUADRANT_ACTUALS";
        IPentahoResultSet results = connection.executeQuery(query);
        try {
            barChart.setValues(results);
            barChart.validate(userSession, null);
            barChart.setParameterProvider(IParameterProvider.SCOPE_REQUEST, requestParameters);
            barChart.setParameterProvider(IParameterProvider.SCOPE_SESSION, sessionParameters);
            // $NON-NLS-1$
            content = barChart.getContent("text/html");
        } finally {
            results.close();
        }
    } finally {
        connection.close();
    }
    return content;
}
Also used : CategoryDatasetChartComponent(org.pentaho.platform.uifoundation.chart.CategoryDatasetChartComponent) IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ArrayList(java.util.ArrayList)

Example 32 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class PentahoFlashChartTest method testHorizontalBarChart.

@Test
public void testHorizontalBarChart() {
    String chart = "<chart>" + "<chart-type>BarChart</chart-type>" + "<orientation>horizontal</orientation>" + "</chart>";
    IPentahoResultSet rs = getRelationData();
    Node chartNode = getChartNode(chart);
    String c2 = PentahoOFC4JChartHelper.generateChartJson(chartNode, rs, false, null);
    assertJsonEquals("{\"y_axis\":{\"colour\":\"#000000\",\"grid-colour\":\"#aaaaaa\",\"stroke\":1," + "\"labels\":[\"Human Resource\",\"Finance\",\"Sales\"],\"offset\":1}," + "\"x_legend\":{\"text\":\"DEPARTMENT\",\"style\":\"font-family: Arial; font-size: 14px; font-weight: " + "normal; font-style: normal;\"},\"elements\":[{\"colour\":\"#006666\",\"text\":\"ACTUAL\"," + "\"values\":[{\"right\":11},{\"right\":14},{\"right\":7}],\"type\":\"hbar\"},{\"colour\":\"#0066CC\"," + "\"text\":\"BUDGET\",\"values\":[{\"right\":12},{\"right\":9},{\"right\":100}],\"type\":\"hbar\"}]," + "\"x_axis\":{\"min\":0,\"colour\":\"#000000\",\"grid-colour\":\"#aaaaaa\",\"stroke\":1,\"max\":121," + "\"labels\":{},\"steps\":11},\"tooltip\":{\"mouse\":2}}", c2, when(IGNORING_ARRAY_ORDER));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Node(org.dom4j.Node) Test(org.junit.Test)

Example 33 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class PentahoFlashChartTest method testPieChart.

@Test
public void testPieChart() {
    String chart = "<chart>" + "<chart-type>PieChart</chart-type>" + "</chart>";
    IPentahoResultSet rs = getRelationData();
    Node chartNode = getChartNode(chart);
    String c2 = PentahoOFC4JChartHelper.generateChartJson(chartNode, rs, false, null);
    assertJsonEquals("{\"y_axis\":{\"min\":0,\"colour\":\"#000000\",\"grid-colour\":\"#aaaaaa\",\"stroke\":1,\"max\":110," + "\"steps\":10},\"x_legend\":{\"text\":\"DEPARTMENT\",\"style\":\"font-family: Arial; font-size: 14px; " + "font-weight: normal; font-style: normal;\"},\"elements\":[{\"animate\":false," + "\"values\":[{\"text\":\"Sales\",\"value\":11,\"label\":\"Sales\"},{\"text\":\"Finance\",\"value\":14," + "\"label\":\"Finance\"},{\"text\":\"Human Resource\",\"value\":7,\"label\":\"Human Resource\"}]," + "\"type\":\"pie\",\"colours\":[\"#006666\",\"#0066CC\",\"#009999\",\"#336699\",\"#339966\",\"#3399FF\"," + "\"#663366\",\"#666666\",\"#666699\",\"#669999\",\"#6699CC\",\"#66CCCC\",\"#993300\",\"#999933\"," + "\"#999966\",\"#999999\",\"#9999CC\",\"#9999FF\",\"#99CC33\",\"#99CCCC\",\"#99CCFF\",\"#CC6600\"," + "\"#CC9933\",\"#CCCC33\",\"#CCCC66\",\"#CCCC99\",\"#CCCCCC\",\"#FF9900\",\"#FFCC00\",\"#FFCC66\"]}]," + "\"x_axis\":{\"colour\":\"#000000\",\"grid-colour\":\"#aaaaaa\",\"stroke\":1," + "\"labels\":{\"labels\":[\"Sales\",\"Finance\",\"Human Resource\"]}}}", c2, when(IGNORING_ARRAY_ORDER));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Node(org.dom4j.Node) Test(org.junit.Test)

Example 34 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class PentahoFlashChartTest method getXYZRelationData.

public static IPentahoResultSet getXYZRelationData() {
    IPentahoResultSet ips = null;
    ArrayList<String> colHeaders = new ArrayList();
    colHeaders.add(0, "DEPARTMENT");
    colHeaders.add(1, "ACTUAL");
    colHeaders.add(2, "BUDGET");
    colHeaders.add(3, "DIFFERENCE");
    ArrayList r1 = new ArrayList();
    r1.add("Sales");
    r1.add(11);
    r1.add(12);
    r1.add(1);
    ArrayList r2 = new ArrayList();
    r2.add("Finance");
    r2.add(14);
    r2.add(9);
    r2.add(5);
    ArrayList r3 = new ArrayList();
    r3.add("Human Resource");
    r3.add(7);
    r3.add(100);
    r3.add(93);
    ArrayList data = new ArrayList();
    data.add(r1);
    data.add(r2);
    data.add(r3);
    ips = MemoryResultSet.createFromLists(colHeaders, data);
    System.out.println(ips.getRowCount());
    return ips;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ArrayList(java.util.ArrayList)

Example 35 with IPentahoResultSet

use of org.pentaho.commons.connection.IPentahoResultSet in project pentaho-platform by pentaho.

the class PentahoFlashChartTest method testBubbleChartDimensional.

@Test
public void testBubbleChartDimensional() {
    String chart = "<chart>" + "<chart-type>BubbleChart</chart-type>" + "<dataset-type>XYZSeriesCollection</dataset-type>" + "</chart>";
    IPentahoResultSet rs = getDimensionalData();
    Node chartNode = getChartNode(chart);
    String c2 = PentahoOFC4JChartHelper.generateChartJson(chartNode, rs, false, null);
    assertJsonEquals("{\"y_axis\":{\"min\":0,\"colour\":\"#000000\",\"grid-colour\":\"#aaaaaa\",\"stroke\":1,\"max\":110," + "\"steps\":10},\"x_legend\":{\"text\":\"ACTUAL\",\"style\":\"font-family: Arial; font-size: 14px; " + "font-weight: normal; font-style: normal;\"},\"elements\":[{\"colour\":\"#006666\",\"dot-size\":1," + "\"text\":\"Sales\",\"values\":[{\"y\":12,\"x\":11}],\"type\":\"scatter\"},{\"colour\":\"#0066CC\"," + "\"dot-size\":5,\"text\":\"Finance\",\"values\":[{\"y\":9,\"x\":14}],\"type\":\"scatter\"}," + "{\"colour\":\"#009999\",\"dot-size\":100,\"text\":\"Human Resource\",\"values\":[{\"y\":100,\"x\":7}]," + "\"type\":\"scatter\"}],\"x_axis\":{\"min\":7,\"colour\":\"#000000\",\"grid-colour\":\"#aaaaaa\"," + "\"stroke\":1,\"max\":14,\"labels\":{}}}", c2, when(IGNORING_ARRAY_ORDER));
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) Node(org.dom4j.Node) Test(org.junit.Test)

Aggregations

IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)113 Test (org.junit.Test)26 Node (org.dom4j.Node)18 ArrayList (java.util.ArrayList)17 IPentahoMetaData (org.pentaho.commons.connection.IPentahoMetaData)12 Iterator (java.util.Iterator)10 List (java.util.List)10 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)10 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)10 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)10 OutputStream (java.io.OutputStream)9 ResultSetCompareAction (org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)8 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)8 XQConnection (org.pentaho.platform.plugin.services.connections.xquery.XQConnection)8 SQLException (java.sql.SQLException)7 HashMap (java.util.HashMap)6 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)6 Map (java.util.Map)5 Set (java.util.Set)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5