Showing posts with label beanshell. Show all posts
Showing posts with label beanshell. Show all posts

Monday, December 12, 2011

Pentaho Dynamic setting Y-Axis


Working on Entando / Pentaho integration, one of the customer request was :
"I needed to be able to change the minimum and maximum Y-axis at run time."

  • Below the solution I've used:
  • create reports
  • insert the chart
  • open the properties window
  • in the scripting language choose BeanShell
  • insert the following script

"
import org.jfree.chart.*;
import org.jfree.chart.axis.NumberAxis;
import java.lang.Double;
data = runtime.getData();
minVal =999999.0;
maxVal = 0.0;
for (int i=0;i latteProd = data.getValueAt(i,2);
if(latteProd < minVal){
minVal = latteProd;
}
if(latteProd > maxVal){
maxVal = latteProd;
}
}
xyPlot = chart.getPlot();
NumberAxis domain = (NumberAxis) xyPlot.getRangeAxis();
domain.setRange((minVal - (minVal*.10)), (maxVal+ (maxVal*.10)));
"