Adding a constant value on a Report's TimeSeriesChart with a refresh

I have a basic report setup with a script that adds a red constant value to a timeseries chart.

If I change the start time of the report to 10:01 AM the following is shown:

but if I change the start time to 10:03 AM the following incorrect is shown:

The problem i presume is the data range no longer includes the constant value. Is there a way to set the Y-axis to always include the constant value even if the actual data isn't within that range?

This is the script I have to add the constant line to the timeserieschart currently.

from java.awt import Color
from java.awt import BasicStroke;
from org.jfree.chart.plot import ValueMarker
	
red = Color(255, 0, 0)
stroke = BasicStroke(2.0)
	
marker = ValueMarker(126, red, stroke)

chart.getPlot().addRangeMarker(marker)

I think you just want to reach into your axis (plot.rangeAxis, probably) and give it an explicit minimum value, maybe 125.5?

https://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/axis/ValueAxis.html#setAutoRangeMinimumSize-double-

1 Like

This did the trick.


chart.getPlot().getRangeAxis().setLowerBound(126)

I would replace the range axis with one that dynamically computed its upper/lower range from the data and any auxiliary values whenever it is asked for upper/lower.

I vaguely recall doing this at one point to deal with Vision's classic chart not calling configureChart() after fresh data arrives. But I only found this:

The technique for delegating range requests to other data instead of constants would be similar to that dynamic range marker.

2 Likes