March 1st, 2010 | Categories: Business Intelligence | Tags:

It is fairly straightforward to read a value stored in a cookie. This can have many uses, for example if the landing page for your reporting application needs to pass some values to your reports but you don’t want them visible in the URL.

The code sample below retrieves the value of a cookie and stores it in a global variable. The code could be placed in one of the startup methods, such as the report’s initialize.


// name of the cookie to read
var cookiename = "birtcookie";
// variable to hold cookie value
var cookieval = "";

// get the hash from the cookie
var request = reportContext.getHttpServletRequest();
var cookies = request.getCookies();
for( var i = 0; i < cookies.length; i++ )
{
  if( cookies[i].getName().equals( cookiename ) )
  {
    cookieval = cookies[i].getValue();
  }
}

// store value in a global variable
reportContext.setPersistentGlobalVariable( "cookieval", cookieval );

February 18th, 2010 | Categories: Business Intelligence | Tags: ,

In a previous post we described how to set the series palette dynamically for a pie chart. A slightly different approach is required for area charts.

Let’s recap on the problem at hand: in what is a fairly common scenario, one chooses the palette colours to match with particular category values. For example, in the chart below “High” is represented in green, “Mid” in orange and “Low” in red.

Area chart with three categories

However, if for a particular dataset of the of category values is not present, the palette colours are still used in the same order, meaning the “Mid” area is now shown as red and “High” as orange. This is confusing for the end user.

Area chart with only two categories, palette colours are confusing

Once again we can solve this issue with some scripting of the chart. In this approach, we will override the beforeDrawSeries method to check for category value and set the fill colour based on that:


function beforeDrawSeries( series, isr, icsc )
{
  // get class of the renderer
  var type = isr.getClass().toString();
  // check for area chart renderer
  if( type == "class org.eclipse.birt.chart.render.Area" )
  {
    // get global counter
    // 1* forces conversion to int
    var i = 1 * icsc.getExternalContext().getScriptable().getPersistentGlobalVariable( "seriesCounter" );
    // get category value
    var val = isr.getSeriesRenderingHints().getDataPoints()[0].getSeriesDisplayValue();
    // set fill colour based on category value
    if( val == "1-Low" )
    {
      isr.getSeriesDefinition().getSeriesPalette().getEntries()[i].set( 242, 88, 106, 128 );
    }
    else if( val == "2-Mid" )
    {
      isr.getSeriesDefinition().getSeriesPalette().getEntries()[i].set( 232, 172, 57, 128 );
    }
    else if( val == "3-High" )
    {
      isr.getSeriesDefinition().getSeriesPalette().getEntries()[i].set( 128, 255, 128, 128 );
    }
    // increment global counter
    i = i + 1;
    // "" forces conversion to string
    icsc.getExternalContext().getScriptable().setPersistentGlobalVariable( "seriesCounter", "" + i );
  }
}

You may have noticed that a global variable seriesCounter is used to hold the reference to the current series. This is because the beforeDrawSeries method is called several times, once for each category value present in the data. Another bit of code is therefore required to define the seriesCounter variable in the initialize method of the report:


reportContext.setPersistentGlobalVariable( "seriesCounter", "0" );

One more point to note is that reportContext.setPersistentGlobalVariable only accepts string values, hence the “hack” to convert between a number and a string every time the value is retrieved or stored.

Area chart with only two categories, palette colours dynamically set

January 13th, 2010 | Categories: Business Intelligence | Tags: ,

BIRT series palette is static by default, meaning colours are applied in the specified order without being tied to the actual category values. This is ok in most cases, however consider the following scenario. In our data we expect three category values, “1-Low”, “2-Mid” and “3-High” and the chart series palette has been set to reflect this. Red colour is first in the list, so it will used for the first category value (“1-Low”) etc.:

Chart series palette

With all three category values in the dataset everything works as expected:

Pie chart with static palette colours and all categories

However, suppose that for a particular dataset the value “1-Low” is not present (perhaps a month when the business is performing well?). In this case the palette colours will still be applied in the same order starting with red, leading to inconsistency and quite possibly confusing the users:

Pie chart with colours from a static palette

This problem can be overcome by dynamically scripting the series colours based on the category value. Two methods need to be scripted, one for the chart itself and the other for the legend (otherwise the chart and the legend will not match!).


function beforeDrawDataPoint( dph, fill, icsc )
{
    var sValue = dph.getBaseDisplayValue();
    if( sValue == "1-Low" )
    {
        fill.set( 242, 88, 106, 255 );
    }
    else if( sValue == "2-Mid" )
    {
        fill.set( 232, 172, 57, 255 );
    }
    else if( sValue == "3-High" )
    {
        fill.set( 128, 255, 128, 255 );
    }
}


function beforeDrawLegendItem( lerh, bounds, icsc )
{
    var sValue = lerh.getLabel().getCaption().getValue();
    var fill = lerh.getFill();
    if( sValue == "1-Low" )
    {
        fill.set( 242, 88, 106, 255 );
    }
    else if( sValue == "2-Mid" )
    {
        fill.set( 232, 172, 57, 255 );
    }
    else if( sValue == "3-High" )
    {
        fill.set( 128, 255, 128, 255 );
    }
}

The set method can take either three integer parameters with values between 0 and 255 for Red, Green, Blue or four integer parameters (RGB + Alpha channel for opacity). After including the above scripts the chart is generated with the correct colours for the category values:

Pie chart with colours dynamically reflecting category values

January 13th, 2010 | Categories: Business Intelligence | Tags: ,

It is possible to set the title of a chart dynamically, for example based on parameter values, using a little bit of scripting. The example below assumes that two parameters are defined (“Year” and “Month” with values such as “2010″ and “Jan”).


function beforeGeneration( chart, icsc )
{
    var sYear = icsc.getExternalContext().getScriptable().getParameterValue( "Year" );
    var sMonth = icsc.getExternalContext().getScriptable().getParameterValue( "Month" );
    var sTitle = "Chart for " + sMonth + " " + sYear;
    chart.getTitle().getLabel().getCaption().setValue( sTitle );
}

The title of the chart will be set dynamically based on report parameter values.

January 12th, 2010 | Categories: Linux | Tags: , ,

VMware Player experiences mouse capture problems when run under Ubuntu 9.10 Karmic host. Inside the guest window, the mouse pointer works fine in a top-left rectangle of the window (640×480 pixels?) but outside of this area the mouse pointer switches its focus to the host. Add the following line to the file /etc/vmware/bootstrap to fix it:

export VMWARE_USE_SHIPPED_GTK=yes

Important note: VMware code needs to be recompiled each time the Linux kernel is updated and this entry may prevent it from compiling successfully. The additional line should be removed or commented out prior to building VMware Player and then put back in back again.

For a discussion see this thread on Ubuntu forums.

January 11th, 2010 | Categories: Business Intelligence | Tags: ,

Eclipse BIRT comes with Report Viewer, a J2EE application used for generating and displaying reports. Whilst deploying and using the out-of-the-box application on Tomcat is straightforward, there are fairly rich configuration and parametrization options which are non-obvious. The following two documents describe how the viewer works and how to control its behaviour.

January 11th, 2010 | Categories: Web | Tags: ,

Follow these steps to change the search engine used by Firefox 3 address bar:

  1. Enter about:config in the browser’s address bar and accept a warning dialog if it appears.
  2. In the filter box type in keyword.URL
  3. Double click the entry and paste in your prefered search engine URL (e.g. http://www.bing.com/search?q=)

You can always revert back to the default Google search by right-clicking the entry and selecting the Reset menu option.

December 16th, 2009 | Categories: Linux | Tags:

Good article on Tuxradar with some clever command line hacks: Command line tricks for smart geeks

November 19th, 2009 | Categories: Business Intelligence | Tags: ,

The BIRT chart wizard provides an option to skip missing values in a series and connect them with the series line; however, there is no option to substitute a default value for the missing data. The screenshot below shows a chart where the series value is missing for category value 03-MAR and the “Connect Missing Values” option has been selected under the value series options:

chart_fill_before

There is no option in the chart wizard to fill in the missing values, i.e. replace them with a default. However, it is possible to achieve this with a simple script. In this case we check for the series name and replace the missing values with 0. To use the script, highlight the chart in the UI and click the Script tab along the bottom of the main window. Then simply paste the script below and save the report.


function afterDataSetFilled( series, dataSet, icsc )
{
  if( series.getSeriesIdentifier() == "Series 1" )
  {
    var list = dataSet.getValues();
    for( var i = 0; i < list.length; i = i + 1 )
    {
      if( list[i] == null )
      {
        list[i] = 0;
      }
    }
  }
}

The screenshot below shows the chart with the script included:

chart_fill_after

November 18th, 2009 | Categories: Linux | Tags: ,

Here’s how to find the version of your CentOS system from the command line:

more /etc/redhat-release