BIRT- methode : can't call or retrieve a data element in Chart API

Hi everyone,
I'm working on a report using BIRT where i need to retrieve a value of a data element (stored in a table) in chart script, spicifically in beforeGeneration() , and use for setting the step size dynamically.
I've tried something like:

params["step"]=this.getRowData().getColumnValue("Max-min/10"); ** //i called first the data element from the table and saved it in a parameter**
unction beforeGeneration( chart, icsc )
{

importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);

xAxis = chart.getBaseAxes()[0];
yAxis = chart.getOrthogonalAxes( xAxis, true)[0];
xscale =xAxis.getScale();
yscale = yAxis.getScale();

xscale.setStep (icsc.getExternalContext().getScriptable().getParameterValue("step")); ** //getting the parameterValue**
}

Unfortunatelly, the chart API does not identify the methode getParameterValue after getScriptable(). I believe this is because the getParameterValue() belongs to the **reportContext ** interface which i can't use in beforeGeneration().

I'm using the ALL-in-one version 4.8.0 and eveything seems to work properly.

So is there anyway that i can get the this data element from my dataset in my chart script?.

I would really appreciate it if you could help me

Thanks in advance
Khaled

Comments

  • Is the data set that contains the step size data the same data set that contains the chart data? If so, you could add the step data as a series, then turn off the visibility for the series on the Format Chart tab. The value should still be accessible in code as a series data point. There is probably a more elegant way to do it. When I have more time, I will look into it.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • Hi Jeff,
    thank you for your answer and for your time. Your suggestion seems very logic, but i still don't know how to call the value of this invisible Series in the beforeGeneration(), since the only way to set the step dynamically is to use the method setStep("my retrieved value") and place it in the beforeGeneration(). This would be like:

    function beforeGeneration( chart, icsc )
    {

    importPackage(Packages.org.eclipse.birt.chart.model.data.impl);
    importPackage(Packages.org.eclipse.birt.chart.model.attribute.impl);

    xAxis = chart.getBaseAxes()[0];
    yAxis = chart.getOrthogonalAxes( xAxis, true)[0];
    xscale =xAxis.getScale();
    yscale = yAxis.getScale();

    xscale.setStep ("hier i must retrieve the value of my hidden Series");
    }

    Please see the following pic for better understanding.

    I hope you'll be able to hepl me with it or anyone else, since i need to the report done till end of this month.

    Thanks alot
    Khaled

  • Hi Khaled,

    I found a way to access a Data Set column value from the chart beforeGeneration script. Here are the steps I used:

    1. Create a 1x1 grid on the top of the report.
    2. In the grid properties, go to the Bindings tab and add a binding to the Data Set. Be sure to include the column containing the "scale" value in the binding.
    3. Insert a Data element in the grid cell. For the Expression in the Data element editor, click "Available Column Bindings" > "Grid" and double click the column so that the expression is row["column name"]. Save the Data element.
    4. Go to the onCreate event of the Data element in the grid and add the following code:

      reportContext.setPersistentGlobalVariable("scale", this.getValue().toString());

    5. In beforeGeneration of the chart script, add the following code:

      importPackage(Packages.org.eclipse.birt.chart.model.attribute);
      var myScale = icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("scale");

    I hope this helps.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • edited August 15

    Hi Jeff,
    thank you very much for your help. I've attached an example after doing exactly as what you posted.
    can you please confirm that what i did is right?

    Thanks is advance

  • I have some meetings. I'll test it when I have time. To check the value, try adding this code after the code in step 5:

    importPackage(Packages.java.lang);
    System.out.println("********************************");
    System.out.println(myScale);

    It should print the value to the Console window.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • edited August 15

    Hi Jeff,
    No plroblem take your time :smile:
    I've tested it. it seems to work on BIRT perfectly (when i preview the report). But when I use the report for the main purpose where i need it (i'm using it as template for displaying xml data that comes from an independent web-software),in this case, all information appear except for the chart, although it works properly on BIRT.

    I've traced the problem by deleting the expression :

    var myScale=icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("step");
    xscale.setStep (myScale);

    and instead i have made my scale fixed as follows :

    var myScale=0,115695
    xscale.setStep (myScale);

    and then I've tried it again on the software and it wokrs 1 to 1.

    So i think the problem is with the method getPersistentGlobalVariable(), because of the following :

    So my question is : what does it mean, when the predicting menu does not display the above method????
    and why i don't see the getPesistentGlobalParameter() in the predicting menu?
    can you try the same code on your version to see if you get the method displayed in the predicting menu?.

    Thank you in advance and looking forward to your help

  • edited August 16

    The difference between the test that works and the test that does not work is not clear to me. I have tested in BIRT, but I am not able to picture the steps you are taking when you run the other test.

    There are numerous methods that do not display in the context (predicting) menu, so I would not read too much into it. I noticed you wrote "getPesistentGlobalParameter()" once. The method I tested is "getPesistentGlobalVariable()".

    I have two suggestions:

    1. A limitation of the Global Variables in BIRT is that they are particular about the data type. In the second test, try converting the value to a String before saving it in the Data element if it is not already a String data type. i.e. myScaleVariable.toString()

    2. Add debug statements like I showed in my previous post before and after the line of code that is not working to see if it is even running. If not, check the logs for error messages.

    Jeff F.
    Customer Support Engineer I
    OpenText
  • Hi jeff,
    Thank you for your thoughts.
    Can you please post how to debug the code or for example to add breakpoints in order to test the code in the chart script. I also would like to learn how to add the console to see my compiled code, because when i tested the output of my Variable, i tested it in report view rather than in console window

    Thanks a lot
    Khaled
  • The chart debugging that I use is simply to add code like:

    importPackage(Packages.java.lang);

    System.out.println(insert string here);

    To show the console window where the messages get printed, restart Eclipse but run eclipsec.exe instead of eclipse.exe.

    Eclipse has a debugger. I think you run it by going to Window menu > Perspective > Open Perspective > Other > Debug. Window > Preferences > Run/Debug has some settings for it. If you search the web on "Eclipse Debugger" you will find more info.

    Also, the browser Dev Tools can be useful.

    Jeff F.
    Customer Support Engineer I
    OpenText
Sign In or Register to comment.