Setting up bound value on chart

Is it possible to have a separate script for having a lower and upper bound value on chart while it has current value of scatter came from dataset query.

For example here in my data, I have my scatter plot in the chart and my aim is to put a dynamic value for its bound that has straight line. Because I tried to check the build in function on chart customizer properties and set the upper and lower bound from both X and Y axes but still does’nt show the bound.

Is there any script or function that will put bound manually on the chart.

output is something like this:

Have you tried something like this

def setChartBounds(chart, min, max):

    plot = chart.getChart().getPlot()
    plot.getDomainAxis().setRange(min, max) # For setting the domain (x) axis bounds or
    plot.getRangeAxis().setRange(min, max) # For setting the range (y) axis bounds.


chart = event.source # Or whatever path to the chart
setChartBounds(chart, 0, 100)

Yes, actually I already tried it and its working but the X and Y axis value will just simply adjust and my expectation is to have a line inside the chart like what I show in image above.

In an EasyChart, use two calculated pens with the Function = Constant. In a classic chart, add another dataset and create a constant dataset with points spanning your chart, connected by a line renderer.

2 Likes

Thank you pturmel, Got it!

You can also add range markers. This example is from the configureChart extension method.

def configureChart(self, chart):

	from org.jfree.chart.plot import ValueMarker
	from java.awt import Color, BasicStroke
		
	plot = chart.getPlot()
	
	stroke = BasicStroke(1.0)

	# Draws a horizontal red line through 12.4
	plot.addRangeMarker(ValueMarker(12.4, Color.RED, stroke))
	# Draws a horizontal blue line through 12.225
	plot.addRangeMarker(ValueMarker(12.225, Color.BLUE, stroke))
	

EDIT:
Changed to fit your example with colors and location of markers :slight_smile:

4 Likes