Dynamicaly Add New dataset

edited December 31, 1969 in Designing Analytics Reports
Hi All,

First of all i would like to know is it possible to add new dataset Dynamically in the report and insert new graph to show values coming from the dataset ?

Thanks

lrnit

Comments

  • edited October 5, 2011
    Hi ,


    I have one table which has three columns and n no of rows.

    1 column is ID (to identify particular row )
    2 column contains Select Statement
    3 column contains Where clause


    Now what i require is call these Select and where fields make a query and run it using the id as parameter to identify row.

    After that i have to show this value in any chart.

    i have been able to do so for predefined no of arguments X.

    By defining X dummy dataset and writing script on open before

    this.queryString = queryN;


    How this could be done dynamically or is it Possible or not?


    Any help will be appreciated.

    Thanks

    lrnit
  • mwilliamsmwilliams BIRT Guru
    edited December 31, 1969
    Sorry for the delay. I was at JavaOne this week. Take a look at this post by John Ward:

    http://www.birt-exchange.org/org/devshare/interactive-reporting/1317-using-the-deapi-to-dynamically-add-a-data-set/

    Regards,

    Michael Williams

    eSignLive Evangelism & Community Manager | eSignLive by VASCO
     
    Find me on:
    Twitter
    Facebook
    Blog
    LinkedIn

    eSignLive Developer Community
     
    Email me:
    Google: [email protected]

  • edited October 10, 2011


    Sorry for the delay. I was at JavaOne this week. Take a look at this post by John Ward:



    http://www.birt-exchange.org/org/devshare/interactive-reporting/1317-using-the-deapi-to-dynamically-add-a-data-set/






    Hi I have added this in my report design beforFactory / Initalize event But it gives error on fist line it self. Am i missing something here ?



    public class ReportEventHandler extends ReportEventAdapter {



    @Override

    public void beforeFactory(IReportDesign report, IReportContext reportContext) {

    super.beforeFactory(report, reportContext);



    try {

    ReportDesignHandle reportDesign = reportContext.getDesignHandle();

    OdaDataSetHandle dataSet = reportDesign.getElementFactory().newOdaDataSet("Data Set", "org.eclipse.birt.report.data.oda.jdbc.JdbcSelectDataSet");



    dataSet.setDataSource("Data Source");

    dataSet.setQueryText("select employeenumber from employees where employeenumber = ?");



    OdaDataSetParameter param = new OdaDataSetParameter();



    param.setName("param_1");

    param.setParamName("empNo");

    param.setNativeName("");

    param.setDataType("integer");

    param.setNativeDataType(4);

    param.setPosition(1);

    param.setIsInput(true);

    param.setIsOutput(false);



    dataSet.getPropertyHandle(DataSetHandle.PARAMETERS_PROP).addItem(param);



    OdaResultSetColumn result = new OdaResultSetColumn();

    result.setColumnName("EMPLOYEENUMBER");

    result.setNativeName("EMPLOYEENUMBER");

    result.setDataType("integer");

    result.setPosition(1);

    result.setNativeDataType(4);

    dataSet.getPropertyHandle(DataSetHandle.RESULT_SET_PROP).addItem(result);



    ColumnHint resultHint = new ColumnHint();

    resultHint.setProperty(ColumnHint.COLUMN_NAME_MEMBER, "EMPLOYEENUMBER");

    resultHint.setProperty(ColumnHint.COLUMN_NAME_MEMBER, "integer");



    dataSet.getPropertyHandle(DataSet.COLUMN_HINTS_PROP).addItem(resultHint);



    //this works

    reportDesign.getDataSets().add(dataSet);



    //and so does this

    //reportDesign.getSlot(ReportDesignHandle.DATA_SET_SLOT).add(dataSet);



    //just saving for debug purposes, you can ignore this

    reportDesign.saveAs("C:/TEMP/MyTestDesign.rptdesign");

    } catch (ContentException e) {

    e.printStackTrace();

    } catch (NameException e) {

    e.printStackTrace();

    } catch (SemanticException e) {

    e.printStackTrace();

    } catch (IOException e) {

    e.printStackTrace();

    }

    }

    }
  • edited December 31, 1969
    Hi ,


    Pls reply. i am still looking for answer.


    thanx

    lrnit
  • How I can execute dynamic query which is set on DataSet inside rptdesign file?
    stageDataSet.setQueryText(dynQuery);

    expected column is not binding on chart/cube , meaning, query on dataSet is set but not executed?

  • yes, its working
    var dataSets = reportContext.getReportRunnable().designHandle.getDesignHandle().getDataSets()
    ....
    newDataSet = reportContext.getReportRunnable().designHandle.getElementFactory().newOdaDataSet("something" + uaIndex)
    newDataSet.setDataSource("JDBC_DataSource");
    newDataSet.setQueryText("select stage_id," + stage.userSpecifiedAnalysis[uaIndex].columnNames.toString() + " from " + stage.userSpecifiedAnalysis[uaIndex].tableName + " where stage_id='" + stage.stageId + "' and journey_id='" + json_param.journeyId + "'")

            dataSets.add(newDataSet);
    
Sign In or Register to comment.