Arif
Arif

Reputation: 61

BIRT Palette scripting: How to access dataset row

If I want to change the color of circles in scatter chart based on a field not being used in the chart, then how do i use that column in script. I mean how can i get the that data...for example

If (row[v_count])>2 fill red color...

The exact code is below

function beforeDrawDataPoint(dph, fill, icsc)
{
//Fill implements Fill interface 
//ImageImpl
//ColorDefinitionImpl
//GradientImpl
//MultipleFillImpl
//EmbeddedImageImpl
//PatternImageImpl

importPackage( Packages.org.eclipse.birt.chart.model.attribute.impl );
val = dph.getOrthogonalValue();
if( fill.getClass().isAssignableFrom(ColorDefinitionImpl)){
if (row[v_count]>2){
    fill.set(255, 0, 0);
}
}
}

but i dont know do i get that v_count column in the script. is there some function to get that column ?

I mean if we are making some calculations based on a column from databinding columns..that is not being used in x or y axis, then how do we access that column in the script..is there some kind of function for that.. I tried row["v_count"], but it is not working.

Arif

Upvotes: 3

Views: 3170

Answers (2)

Sinelc
Sinelc

Reputation: 104

I spend my day look but I did not find the solution, this is my colleague who give me :) So I share.

in my example I had to create a vertical marker for every new year

function beforeGeneration(chart, icsc)
{

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

    var chart = icsc.getChartInstance();
    var yAxis = chart.getBaseAxes()[0];

    //get date series for my case
    series = yAxis.getRuntimeSeries();

    // but if you have multiple series ... (for exemple xaxis)
    for (i = 0; i < series.length; i++){
        var values = series[i].getDataSet().getValues();

        for (j = 0; j < values.length; j++){
            if(j > 1){
                var date1 = values[j-1];
                var date2 = values[j];
                if(date1.getYear() < date2.getYear()){
                    min_ml = MarkerLineImpl.create(yAxis, NumberDataElementImpl.create(j));
                    min_ml.getLabel().getCaption().setValue("Nouveau boitier");
                    min_ml.getLineAttributes().getColor().set(255,0,0);
                }           
            }

        }

    }
}

Upvotes: 0

Simulant
Simulant

Reputation: 20112

You could use "persistent global variables". In any place of your report you can write the following to store and load a global variable. Note that you cannot store Integers but only Strings (but after loading you can cast your Strings back to other types). You could store the Value of your column in the Script of an invisible data field located above your chart, so inside your chart you can read the value.

//store a value
reportContext.setPersistentGlobalVariable("varName", "value");
//load the value
var load = reportContext.getPersistentGlobalVariable("varName");

Upvotes: 1

Related Questions