Setting Range Min and Max values on condition

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
budet
Posts: 3
Joined: Fri May 05, 2017 10:03 am
antibot: No, of course not.

Setting Range Min and Max values on condition

Post by budet » Wed Jul 12, 2017 8:35 am

Hi, All!

I'm working with JasperReports and trying to produce some JFreeChart-based TimeSeries graphs with controlled Max and Min Range Axis values. So if data units are in percents then Min would be 0 and Max would 100. Rest of data should have initial auto-scaling.
What is working fine in designer - for TimeSeriesPlot I'm setting <rangeAxisMinValueExpression> to "$F{units}.equals("%") ? 0 : null" and <rangeAxisMinValueExpression> to "$F{units}.equals("%") ? 100 : null"

I get the desired result in Designer 5.6.0, but then I'm uploading this to JasperReports Server I got an error:
Errors were encountered when compiling report expressions class file: 1. Incompatible conditional operand types int and null value
((java.lang.String)field_units.getValue()).equals("%") ? 0 : null; //$JR_EXPR_ID=30$
2. Incompatible conditional operand types int and null value = ((java.lang.String)field_units.getValue()).equals("%") ? 100 : null; //$JR_EXPR_ID=31$

That is logical, but how to set that value to "nothing" then, please?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Setting Range Min and Max values on condition

Post by paradoxoff » Wed Jul 12, 2017 7:57 pm

I do not know Jasper reports, but the best solution would be to skip that section if a special condition is met.

budet
Posts: 3
Joined: Fri May 05, 2017 10:03 am
antibot: No, of course not.

Re: Setting Range Min and Max values on condition

Post by budet » Thu Jul 13, 2017 7:49 am

I can't skip required chart :-)

I think question is JFreeCharts specific, what condition expression would work for Range Min and Max fields? by default those fields are unpopulated, means null or not set or?
Since int type is used there - what would be proper value?

paradoxoff
Posts: 1634
Joined: Sat Feb 17, 2007 1:51 pm

Re: Setting Range Min and Max values on condition

Post by paradoxoff » Thu Jul 13, 2017 6:22 pm

A ValueAxis always has a non-null value range. The upper and lower limit of this can either be set manually, or can be determined automatically based on the range of the dataset. If the values are set manually, the "auto range calculation mechanism" might be deactivated.
What I meant was if you do not have to set the ranges to a specific value, then do not set the ranges at all. To achieve that, you would need a way to check whether the section in your XML should be evaluated or not. I can't advise on how that could be achieved, because I do not know Jasper reports. Maybe you can ask in a Jasper forum.

Locked