ProductsAI & Analytics

Split Bar Chart, Toggle Between Chart and Table, How to use Script Files Outside the BIRT RCP

This week I got to work on a good charting question. I was asked how you would split a series in a bar chart after n and continue the series at m. This allows the designer to show a chart with large values in a series without making others hard smaller and hard to read.

This is what the chart looks like before:

Attached Image 

And this is what it will look like after we are done:

Attached Image 

The key to making this work is using two charts. The chart on top will display any series that has a value larger than 70% of the maximum series. While the bottom chart will show any series less than 25% of the maximum series.

The first step is to create the data set. I used the following statement.

select distinct country,
sum(creditlimit)as countrytotal
from customers
groupby country

This will select each country and then sum the credit limit. Next I created three computed columns.

  • max – Is an integer and the aggregation is set to max. This will retrieve the maximum value for the chart.
  • min – Is an integer and will get the maximum cutoff for the bottom chart. I used this expression:
    var min = row["max"]*.25;
  • chart2min – Is an integer. This is the minimum scale value for the top chart. I used this expression:
    var value = row["max"]*.70;

The three computed columns that are shown above will do most of the heavy lifting for this report.

Next I created a single cell grid and dragged my entire data set into it. Then I made the table invisible and named it “mytable”. Make sure to name the table because we will be using this as the data source for both charts. 

I need to store the value of row[“chart2min”] as a global persistent variable so I can call it later from the chart script. To do this click on “chart2min” from the table > select the “script” tab > and add the following inside of onCreate()


Now we need to place two charts under the table inside the grid. Starting with the chart on the bottom we will select “mytable” as the data source, use row[“COUNTRY”] as the x-axis, and the following code for the y-axis:

if(row["COUNTRYTOTAL"]> row["min"]){

This will check to see if each series is greater than our 25% cutoff point. If it’s over 25% then the series stays at the 25% max and will continue with the second chart. We also need to remove the chart title and legend. You can remove the title from “Format Chart” > “Chart Area” > “Title” and uncheck visible.
The legend can be hidden from “Chart Area” > “Legend” and uncheck “visible”.

The top chart doesn’t need any logic in the y-series because we will set the minimum scale from beforeGeneration(). So place country in the x-axis and “countrytotal” in the y-axis. 

Now we need to hide the x-axis lines so it looks like one fluid chart. To do this go to “Format Chart” > “Chart Area” > “Axis” > “X-Axis” > “Grid Lines”. From here you will need to uncheck “Show Axis Line” and “Visible” under ticks. You will also need to hide the legend as described from the bottom chart steps.

To set the y-axis minimum scale we need to add the following code to beforeGeneration().

function beforeGeneration( chart, icsc ){
  importPackage( );
  xAxis = chart.getBaseAxes()[0];var value = parseInt(icsc.getExternalContext().getScriptable().getPersistentGlobalVariable("chart2min"));
  yAxis = chart.getOrthogonalAxes( xAxis,true)[0];
  yscale = yAxis.getScale();
  yscale.setMin(NumberDataElementImpl.create( value ));

If everything was done correctly you can now run the report and it will look similar to the second image shown in the beginning. To view the working example you can download it from this devshare.

Some other posts worth taking a look at:

Here are some unanswered posts from this week:

If you have a suggestion or solution for any of these, please post in the thread!

As the week comes to an end I hope everyone has a good weekend and thanks for reading! If you have any questions or comments please feel free to comment below! 

Show More


OpenText is the leader in Enterprise Information Management (EIM). Our EIM products enable businesses to grow faster, lower operational costs, and reduce information governance and security risks by improving business insight, impact and process speed.

Related Posts

Back to top button