Skip to content

Geoprism BIRT Javascript

rrowlands edited this page Oct 29, 2019 · 1 revision

Hide a chart based on the selected categoy

Click on the chart.  In the properties panel, select visibility.  Check the Hide Element checkbox.  Click the javascript syntax button next to the expression input.  Use the following code:

params["category"].value == null || params["category"].value == '' || params["category"].value == '855' 

Dynamically set the chart title

function beforeGeneration( chart, icsc )
{
  var title = icsc.getExternalContext().getScriptable().getParameterValue("categoryLabel");
  chart.getTitle().getLabel().getCaption().setValue("Sales and Earnings over time for " + title);

}

Dynamically set the chart height based upon the number of series

function beforeGeneration( chart, icsc )
{
  var reportContext = icsc.getExternalContext().getScriptable();

     // Dynamically size the height of a chart based upon the number of values

  var xAxis = chart.getBaseAxes()[0];
  var yAxis = chart.getOrthogonalAxes( xAxis, true )[0];        
  var definition = yAxis.getSeriesDefinitions().get(0);
  var allSeries = definition.getRunTimeSeries();
  if(allSeries.size() > 0)
  {            
    var series = allSeries[0];
    //Retrieve list of data values
    var list = series.getDataSet().getValues();
    var length = list.length;
    height = (length / 3 * 50) + 100;
    if (reportContext.getOutputFormat() != "html"){
      height = Math.min(height, 700); 
    }           
    chart.getBlock().getBounds().setHeight(height);
  }

}

Dynamically set the width of the chart based upon the width report parameter

function beforeGeneration( chart, icsc )
{
  var reportContext = icsc.getExternalContext().getScriptable();

    var width = reportContext.getParameterValue("width");       

  if(width != null) {
    chart.getBlock().getBounds().setWidth((width));          
  }      
} 

Dynamically set the color of a bar graph column based upon the selected report label

function beforeDrawDataPoint(dph, fill, icsc)
{
    var label = icsc.getExternalContext().getScriptable().getParameterValue("categoryLabel");
    var val = dph.getBaseDisplayValue();
    if (val == label){
        fill.set(255, 0, 0);
    }
}