# set boundries to throw out 'bad' values that land outside this range
minBoundary = 50
maxBoundary = 100
from org.jfree.data.general import DatasetUtilities
# get the chart, axis, data
plot = chart.getPlot()
rangeAxis = plot.getRangeAxis()
rangeAxis.setAutoRange(False)
ds = plot.dataset
# Find the initial range of the dataset
rangeBounds = DatasetUtilities.findRangeBounds(ds)
rangeMin = rangeBounds.getLowerBound()
rangeMax = rangeBounds.getUpperBound()
# working minimum and maximum values for dataset. these are swapped with the initial values on purpose
currentMin = rangeMax
currentMax = rangeMin
# loop through the dataset to find desired min and max
series = 0 # which pen to search
numItems = ds.getItemCount(series)
for i in range(numItems):
val = ds.getYValue(series,i)
# find lowest value that is above the minBoundary
if val > minBoundary and val < currentMin:
currentMin = val
# find highest value that is below the maxBoundary
if val < maxBoundary and val > currentMax:
currentMax = val
# calculate 10% padding
padding = (currentMax - currentMin) * 0.1
# set bounds in chart
rangeAxis.setLowerBound(currentMin - padding)
rangeAxis.setUpperBound(currentMax + padding)
# for troubleshooting: look in the console after going to the preview pane to see real values
# comment these lines when done with testing
print "Min: ", currentMin
print "Max: ", currentMax
print "Padded Min: ", currentMin - padding
print "Padded Max: ", currentMax + padding |